Search code examples
codenameone

The menu button disappear


I'm trying to develop a side menu with a sliding home screen when I open the menu. The issue I have is when I close the side menu, the menu button disappear . enter enter image description hereimage description here

    Form hi = new Form("Hi World");
    Toolbar tb = new Toolbar(false);
    Image icon = theme.getImage("icon.png");
    Container topBar = new Container(new BorderLayout());
    topBar.add(BorderLayout.SOUTH, new Label("Cool App Tagline...", "SidemenuTagline"));
    topBar.setUIID("SideCommand");
    Command SideLogoCommand = new Command("");
    SideLogoCommand.setIcon(icon);
    
    Command MenuCommand = new Command("");
    
   
    
    Button HomeCommand= new Button("Home");
    HomeCommand.getAllStyles().setFgColor(0xA6A6A6);
    HomeCommand.addActionListener((evt) -> {
        SideMenuBar.closeCurrentMenu();
    });

    Button WebsiteCommand= new Button("Website");
    WebsiteCommand.getAllStyles().setFgColor(0xA6A6A6);
   
    Button SettingsCommand= new Button("Settings");
    SettingsCommand.getAllStyles().setFgColor(0xA6A6A6);

    Container cnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    cnt.add(topBar);
    cnt.add(HomeCommand);
    cnt.add(WebsiteCommand);
    cnt.add(SettingsCommand);
    hi.setToolbar(tb);
    tb.setOnTopSideMenu(false);
    hi.addCommand(SideLogoCommand);
    MenuCommand.putClientProperty("SideComponent", cnt);
    tb.addCommandToSideMenu(MenuCommand);
    
    hi.addComponent(new Label("Hi World"));
    hi.show();

Solution

  • I'm guessing it's because of this line:

    tb.setOnTopSideMenu(false);
    

    You're essentially forcing the older less tested side menu that might still have regressions in newer code. The best thing to do is remove that line. But if you insist you can try invoking:

    hi.setAllowEnableLayoutOnPaint(true);
    

    Notice this will impact performance for long forms etc.