Search code examples
codenameoneside-menu

Codename One nested Sidemenu


I am trying to create a nested side menu for a CN1 application, similar to the one in the screenshot.

For the nested sidemenu to work, I image it has to stay open when the user presses a command of a dropdown list , so that he/ she can choose an option. But the CN1 sidemenu appears to close every time and I couldn't find a workaround.

One approach I was trying was to add an action event to the "hamburger menu ", but this doesn't seem to work.

    Button sideBtn = (Button)((BorderLayout)bar.getLayout()).getEast(); 
    sideBtn.addActionListener(new ActionListener(){ 
        @Override 
        public void actionPerformed(ActionEvent evt) { 
           Toolbar.setPermanentSideMenu(true);
       };

Neither does adding Toolbar.setPermanentSideMenu(true) to any other button's action event.

Anther approach I have in mind is to add hidden buttons to the sidemenu and repaint the toolbar when the button is clicked, but this still does not keep the sidemenu open and seems to be not very direct.

Is there anything more straightforward? What would be the best approach?

Thanks in advance for any kind response. enter image description here


Solution

  • The setPermanentSideMenu method is designed for tablets and not for what you are trying to do. Toggling it after the init(Object) method was invoked doesn't make sense and might break your app.

    You didn't list how you added the button to the side menu but adding it using addComponentToSideMenu(Component) should work (notice I didn't use the version that accepts a Command).