Own Tabs Container of Buttons: how to initialize all of them doing the same?

霸气de小男生 提交于 2019-12-14 02:35:28

问题


I just created my own Container, its structure looks like this:

Container
|- TabsContainer
   |-Button1
   |-Button2
   |-Button3
   ...

It should be like this:

and be positioned at the bottom of the screen, like this:

in every Form I create.

When I add this custom Container to the 4 of my Forms, I still want all of the buttons to do the exact same thing. How could I do this? And In what function? before?

I already tried onPostShow()of my login Screen by getting all of them with their unique component root and adding an actionListener, but it did not work.

Furthermore the tabs are no "blank containers" but still depicting the buttons, but they should not. See here:

How can I solve these two issues?


回答1:


To get this to work globally, you need to add the actionListenerdirectly to the buttons.

After creating your Container and adding the Buttons, right click on them one after the other and select Event -> Action Event. This will generate onComponentAction method where you can write your code for that button.

You should get something similar to this:

@Override
protected void onContainer_Button1Action(Component c, ActionEvent event) {
    //Write all you want this button to do here
}

I'm sure you're trying to avoid code repetition, as mentioned in your previous question. Using universal container is more secure and less prone to errors than the earlier method.

Codename One also supports the EmbeddedContainer functionality in the old GUI builder. So you can create a Container instance for the 6 tabs (in the add new GUI element menu pick "Container") and add them to the tabs as an EmbeddedContainer UI. Note that this isn't supported by the new GUI builder which is based on a more traditional GUI builder approach and it might make navigation behavior in the app somewhat "odd".

In the new GUI builder you can just write generic code to map to this as the form would just map directly to a single class.



来源:https://stackoverflow.com/questions/35065950/own-tabs-container-of-buttons-how-to-initialize-all-of-them-doing-the-same

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!