Java CN1:更改选项卡中内容的背景色

Java CN1:更改选项卡中内容的背景色,java,codenameone,Java,Codenameone,我有一段代码: //Tabs for filter Tabs t = new Tabs(); Style s = UIManager.getInstance().getComponentStyle("Tab"); FontImage icon1 = FontImage.createMaterial(FontImage.MATERIAL_QUESTION_ANSWER, s); t.addTab("All", icon1, conOrders); //t.a

我有一段代码:

//Tabs for filter
    Tabs t = new Tabs();
    Style s = UIManager.getInstance().getComponentStyle("Tab");
    FontImage icon1 = FontImage.createMaterial(FontImage.MATERIAL_QUESTION_ANSWER, s);
    t.addTab("All", icon1, conOrders);
    //t.addTab("Done", icon1, conOrdersCompleted);
    t.addTab("Processing", icon1, conOrdersProcessing);
    this.add(t);
    initGuiBuilderComponents(resourceObjectInstance);
现在我想更改“内容”选项卡的背景色。现在看起来是这样的:


我希望红色区域的背景是白色。我正在使用新的GUI builder。

如果您希望每个选项卡具有不同的颜色,只需执行以下操作:

conOrdersProcessing.setUIID("Tab1Background");
并相应地设置样式。这可能是最好的办法

您还可以使用UIID设置
选项卡
容器的各个部分的样式:


选项卡窗格
选项卡容器
选项卡
。请注意,您可以在模拟器中使用Component Inspector工具来发现组件的UIID。

我目前正在处理CN1中的选项卡,使用相同的想法来分别设置选项卡的样式。下面的代码是对示例的改编

要使其工作,您需要激活内部css支持,或者在主题编辑器中添加UIID

    Tabs tb = new Tabs() {
        @Override
        protected Component createTab(String title, Image icon) {
            SpanButton custom = new SpanButton(title);
            custom.setIcon(icon);
            custom.setUIID(title); // title of the tabs, stylable background 
            custom.setTextUIID("Tab");
            custom.setIconPosition(BorderLayout.NORTH);
            custom.setIconUIID(title);
            return custom;
        }

        @Override
        protected void setTabSelectedIcon(Component tab, Image icon) {
            ((SpanButton) tab).setPressedIcon(icon);
        }

        protected void selectTab(Component tab) {
        }

        @Override
        protected void bindTabActionListener(Component tab, ActionListener l) {
            ((SpanButton) tab).addActionListener(l);
        }
    };

    Container container1 = BoxLayout.encloseY(labelOne, labelTwo);
    Container container2 = BoxLayout.encloseY(labelThree, labelFour);

    // style the containers inside the tabs
    container1.setUIID("Tab1Background");
    container2.setUIID("Tab2Background");

    // when adding the tabs, the title matches the UIID in css style-sheet
    tb.addTab("Tab1Background", FontImage.MATERIAL_3D_ROTATION, 4, container1);
    tb.addTab("Tab2Background", FontImage.MATERIAL_ACCESSIBILITY, 4, container2);

    // css

    Tab1Background {

        background-color: red;
        text-align: center;
    }

    Tab2Background {

        background-color: yellow;
        text-align: center;
     }

谢谢你的回答。如何相应地设置样式?例如,在CSS或Designer中将
选项卡设置为白色您做了什么会导致这种情况?你是如何设计这里的用户界面的?我刚刚在CN1设置中添加了一个css文件。然后,整个样式发生了变化。如果添加CSS,则会删除主题文件。我说CSS或designer是因为我不知道你在用什么。我建议在设置中取消选择CSS,并从备份中恢复旧的资源文件。