自己的选项卡容器按钮:如何初始化所有的按钮都一样? [英] Own Tabs Container of Buttons: how to initialize all of them doing the same?

查看:70
本文介绍了自己的选项卡容器按钮:如何初始化所有的按钮都一样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚创建了自己的容器,其结构如下:

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

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

应该是这样的:

并位于屏幕底部,如下所示:

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?

我已经尝试过登录屏幕的 onPostShow(),方法是使用所有组件的唯一组件根目录并添加它们

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?

推荐答案

要使其全局运行,您需要添加 actionListener 直接移至按钮。

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

创建容器并添加按钮后,一个接一个地右键单击它们,然后选择 Event-> Action活动。这将生成onComponentAction方法,您可以在其中编写该按钮的代码。

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.

代号One 还支持旧的GUI构建器中的 EmbeddedContainer 功能。因此,您可以为6个选项卡创建一个 Container 实例(在添加新的GUI元素菜单中选择 Container),并将它们作为 EmbeddedContainer UI。请注意,基于更传统的GUI构建器方法的新GUI构建器不支持此功能,它可能会使应用程序中的导航行为有些奇怪。

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".

新的GUI构建器中,您只需编写通用代码即可进行映射因为表单将直接映射到单个类。

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.

这篇关于自己的选项卡容器按钮:如何初始化所有的按钮都一样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆