Put some components when i click into menu (SOS)


i am trying to make my first vaading application and i am frustating. i am one week working with this but i fail
i am not able, i dont know and i fail to pot some component into one page.
My firts app has one menu bar and i want that when i clicl into some menu componen to put into other layout (bellow) some componets, one form.
can you help me?
bellow i put my basic code,i appreciate any suggestions

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.logging.Level;

import com.goikogane.admin.componentes.visuales.FormularioAltaNoticia;
import com.goikogane.admin.componentes.visuales.GoikoganeAdminBarraMenuGeneral;
import com.goikogane.admin.componentes.visuales.PaginaVacia;
import com.vaadin.Application;
import com.vaadin.event.FieldEvents;
import com.vaadin.event.FieldEvents.BlurEvent;
import com.vaadin.terminal.ThemeResource;
import com.vaadin.ui.Button;
import com.vaadin.ui.AbstractSelect.Filtering;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.MenuBar.Command;
import com.vaadin.ui.MenuBar.MenuItem;
import com.vaadin.ui.Window.Notification;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.DateField;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.MenuBar;
import com.vaadin.ui.Panel;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;

public class GoikoganeAdminMainServlet extends Application {
	final Window mainWindow = new Window("EXAMPLE Vaadin Application");
	//final MenuBar menubar = new MenuBar();

	HorizontalLayout layout1 = new HorizontalLayout();
	HorizontalLayout layout2 = new HorizontalLayout();
	HorizontalLayout centralMainLayout = new HorizontalLayout();

	Panel panel1 = new Panel();
	Panel panel2 = new Panel();

	final String width = "100%";
	public static String MENU=null;
	final MenuBar menubar = new MenuBar();

	public void init() {
		HorizontalLayout menuLayout = new HorizontalLayout();
		MenuBar.MenuItem excursionesMI = menubar.addItem("Excursiones", null, null);
		MenuBar.MenuItem telefonosMI = menubar.addItem("Telefonos", null, null);
		MenuBar.MenuItem noticiasMI = menubar.addItem("Noticias", null, null);
		MenuBar.MenuItem travesiasMI = menubar.addItem("Travesias", null, null);
		MenuBar.MenuItem marchasMI = menubar.addItem("Marchas", null, null);
		MenuBar.MenuItem cuotasMI = menubar.addItem("Cuotas", null, null);
		MenuBar.MenuItem cursosMI = menubar.addItem("Cursos", null, null);
		MenuBar.MenuItem consursosMI = menubar.addItem("Concursos", null, null);
		MenuBar.MenuItem articulosMI = menubar.addItem("Articulos", null, null);
		MenuBar.MenuItem imagenesMI = menubar.addItem("Imágenes", null, null);
		MenuBar.MenuItem cimasMI = menubar.addItem("Cimas", null, null);
		MenuBar.MenuItem sociosMI = menubar.addItem("Socios", null, null);

		MenuBar.MenuItem excursionesMII = excursionesMI.addItem("Listar todas de esta año", menuCommand);
		excursionesMII = excursionesMI.addItem("Buscar Una", menuCommand);

		MenuBar.MenuItem telefonosMII = telefonosMI.addItem("Listar todas de esta año", menuCommand);
		telefonosMII = telefonosMI.addItem("Buscar Una", menuCommand);

		MenuBar.MenuItem noticiasMII = noticiasMI.addItem("Listar todas de esta año", menuCommand);
		noticiasMII = noticiasMI.addItem("Buscar Una", menuCommand);

		MenuBar.MenuItem travesiasMII = travesiasMI.addItem("Listar todas de esta año", menuCommand);
		travesiasMII = travesiasMI.addItem("Buscar Una", menuCommand);

		MenuBar.MenuItem marchasMII = marchasMI.addItem("Listar todas de esta año", menuCommand);
		marchasMII = marchasMI.addItem("Buscar Una", menuCommand);

		MenuBar.MenuItem cuotasMII = cuotasMI.addItem("Listar todas de esta año", menuCommand);
		cuotasMII = cuotasMI.addItem("Buscar Una", menuCommand);

		MenuBar.MenuItem cursosMII = cursosMI.addItem("Listar todas de esta año",menuCommand);
		cursosMII = cursosMI.addItem("Buscar Una", menuCommand);

		MenuBar.MenuItem consursosMII = consursosMI.addItem("Listar todas de esta año", menuCommand);
		consursosMII = consursosMI.addItem("Buscar Una", menuCommand);

		MenuBar.MenuItem articulosMII = articulosMI.addItem("Listar todas de esta año", menuCommand);
		articulosMII = articulosMI.addItem("Buscar Una", menuCommand);

		MenuBar.MenuItem imagenesMII = imagenesMI.addItem("Listar todas de esta año", menuCommand);
		imagenesMII = imagenesMI.addItem("Buscar Una", menuCommand);

		MenuBar.MenuItem cimasMII = cimasMI.addItem("Listar todas de esta año", menuCommand);
		cimasMII = cimasMI.addItem("Buscar Una", menuCommand);

		MenuBar.MenuItem sociosMII = sociosMI.addItem("Listar todas de esta año",menuCommand);
		sociosMII = sociosMI.addItem("Buscar Una", menuCommand);



	private Command menuCommand = new Command() { 
        public void menuSelected(MenuItem selectedItem) { 
        	System.out.println("MNEU: " + MENU);
        	System.out.println("MNEU: " + selectedItem.getText());
        	if(MENU.equals("....Listar todas de esta año")){

//here the code for putting one form into the layout2
        		FormularioAltaNoticia f = new FormularioAltaNoticia();

into the private method i am tring to put the components but it does’t work



You’d be better off to store references to the different menu items so that you can identify the correct action in the menuSelected() method instead of having to compare strings in order to determine what to do. Comparing strings is not very robust and you’ll easily get errors as the one you have, where you are comparing the text of the menu item “Listar todas de esta año” while you check if it is equal to “…Listar todas de esta año”, which will always be false.

Furthermore try to put only one layout in the main window using setContent() and then add components and layouts to this layout instead of calling mainWindow.addComponent(). It’s not recommended to call setMainWindow() more than once, but you should replace the contents of the window instead.


public void init() {
  Window mainWindow = new Window("foo");

private void other() {

To further simplify your code, you can build the entire layout hierarchy once and then just switch one of the layouts or components in your Command.