Dinamic Menu

Hi:

I’m trying to modify a menubar item when I click another component, but it doesn’t refresh automatically, changing only when I refresh the application…how can I do this without refreshing the browser??

regards,

Hugo

Can you be a bit more specific, ideally with a small code snippet illustrating your design?

Sure, here it goes:

I have a class implementing the menu:

public class Menu000_General extends MenuBar {
	
public Menu000_General(Ver003Application app, String activo) {

		
		MenuItem activoMenu = addItem(activo, null);
		
		
		setWidth("100%");
	}

and here is the getter for it, in the main application class:

private Menu000_General getMenu000_General(){
		if (menu000_General==null){
			menu000_General=new Menu000_General(this, activo);
		}
		
		return menu000_General;
	}

which is called at:

private void setMainComponent(Component c) {
				
		main.addComponent(getMenu000_General());

    }

when I change something in a tabsheet:

public void selectedTabChange(SelectedTabChangeEvent event) {
		
		final TabSheet selectedtabsheet = event.getTabSheet();
		
		if (selectedtabsheet == tabPrincipal) {
			
            activetab1 = selectedtabsheet.getSelectedTab();
            activetab1caption = (selectedtabsheet.getTab(activetab1)).getCaption();

			tab1.setValue(activetab1caption);

		} else {
			
			activetab2 = selectedtabsheet.getSelectedTab();
            activetab2caption = (selectedtabsheet.getTab(activetab2)).getCaption();

			tab2.setValue(activetab2caption);
			
		}
		CambiarMenu(activetab1caption, activetab2caption);
	}


		public void CambiarMenu(String activetab1caption, String activetab2caption){
			
				activo = activetab1caption + " > " + activetab2caption;
				menu000_General=new Menu000_General(this, activo);
				getMenu000_General();
	}

What this basically does is that since I have a tabsheet inside another tabsheet, when I click any of them I want to have a menu item in the menu that says “tab1 > tab2”.

I currently can do it, but I need to refresh the application to make it appear as a menu item

Thank you very much for all your help

Does someone have an answer for this?..please help, I’m stiil stuck in this…

thanks!!!1

I posted this reply in other message, which is related to this, regarding the use of the menuCommand:

thanks!!!

anything???no??

thanks in advance for any possible help…

Your function CambiarMenu does not do what you think.


                //this creates a new menu
                menu000_General=new Menu000_General(this, activo);
                 //this does nothing (returns the new menu but is unused)
                getMenu000_General();

Maybe you are looking for something like this :


                //save the old menu
                Menu000_General oldMenu = getMenu000_General();

                //this creates a new menu
                menu000_General=new Menu000_General(this, activo);

                 //this replaces the old menu by the new one (same main as in function setMainComponent)
                main.replaceComponent(oldMenu, menu000_General);

PS : Your classes and variables names makes the code really hard to read…

Mathias:

Your solution worked perfect. Thank you very much!!!

PS: I know the names are a kinda messy, so sorry if because of that, this took too much of your time…

regards, and thank you very much again.

Hugo