1. #1
    Sencha User
    Join Date
    Apr 2009
    Posts
    4
    Vote Rating
    0
    Achmad Amri is on a distinguished road

      0  

    Default Menu Create on Run Time

    Menu Create on Run Time


    Dear All,

    I having trouble with EXT GWT Menu.

    I want to create menu on run time, but nothing happens with the page although the method for create menu invoked.

    Code
    Code:
    public class MainForm extends LayoutContainer {
        @Override
        protected void onRender(Element parent, int index) {
            super.onRender(parent, index);
    
            Button btnAdd = new Button("Add", new SelectionListener<ButtonEvent>() {
                @Override
                public void componentSelected(ButtonEvent ce) {
                    createMenu();
                }
            });
            add(btnAdd);
        }
        
        private void createMenu() {
            // Start of Admin
            Menu menu = new Menu();
          
            MenuItem sub = new MenuItem("Company Info");  
            menu.add(sub);  
          
            Menu sub_sub = new Menu();
            
            MenuItem miGeneral = new MenuItem("General", new SelectionListener<MenuEvent>() {
                @Override
                public void componentSelected(MenuEvent ce) {
                    WindowCompanyProfile.getWindow().show();
                }
            });
            sub_sub.add(miGeneral);
            
            MenuItem miLocations = new MenuItem("Locations");
            sub_sub.add(miLocations);
            
            MenuItem miCompanyStructure = new MenuItem("Company Structure");
            sub_sub.add(miCompanyStructure);
            
            MenuItem miCompanyProperty = new MenuItem("Company Property");
            sub_sub.add(miCompanyProperty);
            
            sub.setSubMenu(sub_sub);
          
            MenuBar bar = new MenuBar();  
            bar.setBorders(true);  
            bar.setStyleAttribute("borderTop", "none");  
            bar.add(new MenuBarItem("Admin", menu));
            // End of Admin
    
            final ContentPanel panel = new ContentPanel();
            panel.setHeaderVisible(false);
            panel.setSize("100%", "100%");
            panel.setTopComponent(bar);
            
            add(panel, new FlowData(0));
        }
    }
    Any suggestions?

  2. #2
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,734
    Vote Rating
    90
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    Note: you are posting in the Ext GWT 3 forum, whereas your code appears to be based on Ext GWT 2.

    Without seeing how MainForm is created, used, it will be hard to say for sure, but it may be necessary to call layout() after calling add() at the end of the createMenu method.

  3. #3
    Sencha User
    Join Date
    Apr 2009
    Posts
    4
    Vote Rating
    0
    Achmad Amri is on a distinguished road

      0  

    Default


    Sorry, I have been wrong to put this thread into the correct Category. This thread supposed to be in the Ext GWT 2.

    The problem is solved, with adding layout() at the end of the createMenu method. Thanks Colin.

    Code
    Code:
    public class MainForm extends LayoutContainer {
        @Override
        protected void onRender(Element parent, int index) {
            super.onRender(parent, index);
    
            Button btnAdd = new Button("Add", new SelectionListener<ButtonEvent>() {
                @Override
                public void componentSelected(ButtonEvent ce) {
                    createMenu();
                }
            });
            add(btnAdd);
        }
        
        private void createMenu() {
            // Start of Admin
            Menu menu = new Menu();
          
            MenuItem sub = new MenuItem("Company Info");  
            menu.add(sub);  
          
            Menu sub_sub = new Menu();
            
            MenuItem miGeneral = new MenuItem("General", new SelectionListener<MenuEvent>() {
                @Override
                public void componentSelected(MenuEvent ce) {
                    WindowCompanyProfile.getWindow().show();
                }
            });
            sub_sub.add(miGeneral);
            
            MenuItem miLocations = new MenuItem("Locations");
            sub_sub.add(miLocations);
            
            MenuItem miCompanyStructure = new MenuItem("Company Structure");
            sub_sub.add(miCompanyStructure);
            
            MenuItem miCompanyProperty = new MenuItem("Company Property");
            sub_sub.add(miCompanyProperty);
            
            sub.setSubMenu(sub_sub);
          
            MenuBar bar = new MenuBar();  
            bar.setBorders(true);  
            bar.setStyleAttribute("borderTop", "none");  
            bar.add(new MenuBarItem("Admin", menu));
            // End of Admin
    
            final ContentPanel panel = new ContentPanel();
            panel.setHeaderVisible(false);
            panel.setSize("100%", "100%");
            panel.setTopComponent(bar);
            
            add(panel, new FlowData(0));
            layout();
        }
    }

Thread Participants: 1