How to have a right side menu, with container in it

85 views
Skip to first unread message

Gareth Murfin

unread,
Aug 3, 2016, 7:15:42 AM8/3/16
to CodenameOne Discussions
No matter how often I try, I find the whole side menu thing quite confusing. Until now I have had to avoid right hand side menus because I simply cannot get them to work. Left hand side I have been able to get working using Toolbar, roughly something like this:

Toolbar toolbarForLeftMenu;

if (toolbarForLeftMenu==null)
        {
            toolbarForLeftMenu = new Toolbar();
        }
        
        toolbarForLeftMenu.setHidden(true);
        f.setToolbar(toolbarForLeftMenu);
    
        final Container SideMenuLEFT = (Container)this.createContainer(resources, "SideMenuLEFT");
  
        toolbarForLeftMenu.addComponentToSideMenu(SideMenuLEFT);

That works great. However I also need a right menu, which you cannot do with the Toolbar  as far as I am aware. So I am trying to add a right menu by using SideMenuBar, this actually opens up the side bar fine but I cannot work out how to actually add my container to it, here is what I am doing, but it always remains empty:

final Container SideMenuRIGHT = (Container)this.createContainer(resources, "SideMenuRIGHT");        
        
        if (smbForRightMenu==null)
        {
            smbForRightMenu = (SideMenuBar) Display.getInstance().getCurrent().getMenuBar();
            smbForRightMenu.add(SideMenuRIGHT);
            smbForRightMenu.putClientProperty("SideComponent", smbForRightMenu);//revalidate();
            _("added content to the right menu...");
        }
        smbForRightMenu.openMenu(SideMenuBar.COMMAND_PLACEMENT_VALUE_RIGHT);

So basically my question is, why doesnt my container (SideMenuRIGHT) appear on the right menu when it opens up ?





Gareth Murfin

unread,
Aug 3, 2016, 7:16:56 AM8/3/16
to CodenameOne Discussions
there was a typo in that code i meant to put: 

smbForRightMenu.add(SideMenuRIGHT);
            smbForRightMenu.putClientProperty("SideComponent", SideMenuRIGHT);

I tried the second approach just in case, think I read it on the blog, but neither seem to do it.

Shai Almog

unread,
Aug 4, 2016, 12:53:14 AM8/4/16
to CodenameOne Discussions
You need to set the side component before adding the command.

Gareth Murfin

unread,
Aug 4, 2016, 9:27:57 AM8/4/16
to CodenameOne Discussions
Im not 100% clear what you mean, do you mean basically this:

smbForRightMenu.putClientProperty("SideComponent", SideMenuRIGHT);
            smbForRightMenu.add(SideMenuRIGHT);

Still stays empty if I try that.

Gareth Murfin

unread,
Aug 4, 2016, 11:29:18 AM8/4/16
to CodenameOne Discussions
Another strange issue is on the simulator the right menu comes out as expected, you can see the edge of the right side of the screen, but on the device you can see the left side of the screen (which is wrong I believe) see this: https://dl.dropboxusercontent.com/u/4194619/sideMenuIssuey.jpg

Gareth Murfin

unread,
Aug 4, 2016, 11:39:58 AM8/4/16
to CodenameOne Discussions
PS. it appears fine all the way as the menu is moving, its only right at the end when it stops moving that the wrong bit of screen is drawn to the left of it, and remains that way.

Shai Almog

unread,
Aug 5, 2016, 2:19:40 AM8/5/16
to CodenameOne Discussions
That looks like a side menu shadow.

What's SideMenuRIGHT?
Is it a command?
It seems you put it into the client property instead of the container.

Gareth Murfin

unread,
Aug 5, 2016, 8:40:45 AM8/5/16
to CodenameOne Discussions
SideMenuRIGHT is a container which contains what I want my menu to show.

--
You received this message because you are subscribed to a topic in the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/codenameone-discussions/RGuV-ShwvLo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to codenameone-discussions+unsub...@googlegroups.com.
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/69d0ec12-8134-44b5-a85a-523be6b88b1b%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Gareth Murfin
(Android Freelancer - www.garethmurfin.co.uk)

Gareth Murfin

unread,
Aug 5, 2016, 8:54:16 AM8/5/16
to CodenameOne Discussions
Can you show me the minimal amount of lines needed to add a simple label to the right menu? 

It would be great if all the menu and toolbar stuff was wrapped up somehow and slightly less confusing. Mind you I am quite bad at understanding APIs at times :)

Shai Almog

unread,
Aug 6, 2016, 1:25:01 AM8/6/16
to CodenameOne Discussions
If it's the container then you need to have a command and put the client property into that then add the command.

Gareth Murfin

unread,
Aug 26, 2016, 5:08:54 AM8/26/16
to CodenameOne Discussions
It doesnt work, would be great if you could give an example, for now Im just actually going to tell clients you cant have a right menu, far too confusing and hard to do, wasted days trying to get something to appear

Gareth Murfin

unread,
Aug 26, 2016, 6:04:10 AM8/26/16
to CodenameOne Discussions
Works only if I have that title bar thing showing which I dont want I want my own button to pop open a menu on the right, on the left its a piece of cake, im not going to try with layerlayouts and animating them in

Shai Almog

unread,
Aug 27, 2016, 1:52:30 AM8/27/16
to CodenameOne Discussions
I guess there are some dependencies there.  We might restore this functionality to the toolbar at some later date but after the problematic experience in the past with right side navigation we aren't in a hurry.
Reply all
Reply to author
Forward
0 new messages