在顶部菜单中添加组件

时间:2018-01-04 18:20:13

标签: codenameone

我在onTop侧面菜单中添加了一个按钮,该按钮是容器的主要组件。但是单击任一按钮或其他组件无效。我怎样才能使它工作?此外,我在onTop侧面菜单中浏览了南方组件的博客。我已经将cn1更新为8.1,它给出了#34;您的项目库是最新的"但我仍然无法使用它(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(new Label(" 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]]

如果我将表单布局更改为boxlayout 即。 super(新的BoxLayout(BoxLayout.Y_AXIS)),它给出了以下错误

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)

1 个答案:

答案 0 :(得分:1)

谢谢,这是当前实现中的一个错误。我committed this fix

该修复程序将作为2018年1月19日标准星期五更新流程的一部分提供。