Add components in on Top side menu

1

I've added component in onTop side menu with a button which is lead component of the container. But clicking either button or other component has no effect. How can I make it work? Moreover I've gone through a blog for south component in onTop side menu. I've updated the cn1 to 8.1 and it gives "Your project libs are up to date" but still I cannot use it(setComponentToSideMenuSouth). I want to keep the component at the top of the side menu, so will setComponentToSideMenuNorth also exists?

Button userArea = new Button("lead Btn");
userArea.addActionListener(e->{
    System.out.println("bbeck");
});

TextArea emailArea = new TextArea("abc");

Container userInfoContainer = BoxLayout.encloseY(userArea, emailArea);
    Container profileContainer = new Container(new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER));
profileContainer.add(BorderLayout.CENTER, userInfoContainer);
profileContainer.add(BorderLayout.East, new Label("abc));
profileContainer.setLeadComponent(userArea);

f.getToolbar().addComponentToSideMenu(profileContainer);

Update:

public void start() {
    if(current != null){
        current.show();
        return;
    }
    Form hi = new Form("Hi World", BoxLayout.y());
    hi.add(new Label("Hi World"));
    hi.show();

    hi.getToolbar().setComponentToSideMenuSouth(new Label("abc"));

    Command abc = new Command("abc"){

        @Override
        public void actionPerformed(ActionEvent evt) {
            System.out.println("bibek");
        }

    };
    hi.getToolbar().addCommandToSideMenu(abc);
}

Here adding getToolbar().setComponentToSideMenuSouth(new Label("abc")); in a form does nothing (theres no side menu). And as soon as "addCommandToSideMenu(cmd)" is added, it doesn't compile & gives following error

java.lang.IllegalArgumentException: Component is already contained in Container: Container[x=0 y=0 width=0 height=0 name=null, layout = BorderLayout, scrollableX = false, scrollableY = false, components = [Container]]

if I change form layout to boxlayout ie. super(new BoxLayout(BoxLayout.Y_AXIS)) , it gives following error

java.lang.IllegalArgumentException: Component is already contained in Container: Container[x=0 y=0 width=0 height=0 name=null, layout = BorderLayout, scrollableX = false, scrollableY = false, components = [Container]]

Error log:

WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.
java.lang.IllegalArgumentException: Component is already contained in Container: Container[x=0 y=0 width=0 height=0 name=null, layout = BorderLayout, scrollableX = false, scrollableY = false, components = [Container]]
    at com.codename1.ui.Container.insertComponentAtImpl(Container.java:717)
    at com.codename1.ui.Container.insertComponentAt(Container.java:708)
    at com.codename1.ui.Container.addComponent(Container.java:652)
    at com.codename1.components.InteractionDialog.addComponent(InteractionDialog.java:161)
    at com.codename1.ui.Container.add(Container.java:281)
    at com.codename1.ui.Toolbar.constructOnTopSideMenu(Toolbar.java:897)
    at com.codename1.ui.Toolbar.addCommandToSideMenu(Toolbar.java:771)
    at com.bbeck.zzz.aaa.start(Application.java:56)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.codename1.impl.javase.Executor$1$1.run(Executor.java:123)
    at com.codename1.ui.Display.processSerialCalls(Display.java:1116)
    at com.codename1.ui.Display.mainEDTLoop(Display.java:911)
    at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
    at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
Java Result: 1
BUILD SUCCESSFUL (total time: 22 seconds)
codenameone
asked on Stack Overflow Jan 4, 2018 by Amrita Stha • edited Jan 15, 2018 by Amrita Stha

1 Answer

1

Thanks, this is a bug in the current implementation. I committed this fix.

The fix will be available as part of our standard Friday update process on January 19th 2018.

answered on Stack Overflow Jan 16, 2018 by Shai Almog

User contributions licensed under CC BY-SA 3.0