Codenameone 在顶部菜单中添加组件

Codenameone 在顶部菜单中添加组件,codenameone,Codenameone,我在onTop侧菜单中添加了一个组件,其中有一个按钮是容器的主要组件。但单击任何一个按钮或其他组件都没有效果。我怎样才能让它工作?此外,我还浏览了onTop侧菜单中的south组件的博客。我已经将cn1更新为8.1,它给出了“您的项目库是最新的”,但我仍然不能使用它(setComponentToSideMenuSouth)。我想让组件保持在侧菜单的顶部,那么setComponentToSideMenuNorth是否也存在 Button userArea = new Button("lead Bt

我在onTop侧菜单中添加了一个组件,其中有一个按钮是容器的主要组件。但单击任何一个按钮或其他组件都没有效果。我怎样才能让它工作?此外,我还浏览了onTop侧菜单中的south组件的博客。我已经将cn1更新为8.1,它给出了“您的项目库是最新的”,但我仍然不能使用它(setComponentToSideMenuSouth)。我想让组件保持在侧菜单的顶部,那么setComponentToSideMenuNorth是否也存在

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);
更新:

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);
}
这里添加getToolbar().setComponentToSideMenuSouth(新标签(“abc”));在表单中什么都不做(没有附带菜单)。一旦添加了“addCommandToSideMenu(cmd)”,它就不会编译&并给出以下错误

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]]
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]]
如果我将表单布局更改为boxlayout 即super(新的BoxLayout(BoxLayout.Y_轴)),它给出以下错误

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]]
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]]
错误日志:

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)

谢谢,这是当前实现中的一个bug。我


该补丁将于2018年1月19日作为我们标准周五更新流程的一部分提供。

什么是
profileContainer
?似乎您有一个编译问题,因为
East
应该是
East
setComponentToSideMenuSouth
应该可以与当前的项目库配合使用。是否尝试使用工具栏进行编译。setComponentToSideMenuSouth(新标签())编译吗?请注意,netbeans有时会将内容标记为红色,但仍会编译itprofileContainer。jst是一个带有Borderlayout的容器。代码是东方的(我在上面的问题中犯了错误。对不起。请注意,容器中已存在update UpperComponent,这是一个例外,堆栈跟踪将指向一条线,您正在添加一个已添加到其他容器中的组件。South不会生成侧菜单,它只会将一个组件添加到现有侧菜单的底部。)NU如果我使用setComponentToSideMenuSouth或addCommandToSideMenu,它不会给出容器内的异常。如果两者都使用,它会给出指向setComponentToSideMenuSouth()的异常Line什么是完整的堆栈跟踪?我们可以如何在north/on-top中添加组件?只需使用现有的添加API添加它们。默认情况下,组件位于主UI上方请参见