Set the Background Color for JTabbedPane

后端 未结 6 894
傲寒
傲寒 2021-01-06 13:20

I am using Nimbus Look and feel. I needs to change the Background color and foreground color of the tab in JTabbedPane but the color doesn\'t set in JTabbedPane. I tried set

6条回答
  •  死守一世寂寞
    2021-01-06 14:07

    If you want to change the actual content, there are two useful methods of the tabbed pane: setForegroundAt and setBackgroundAt. You can just loop through all the tabs and call these:

    for (int i = 0; i < pane.getTabCount(); i++) {
        pane.setForegroundAt(i, foregroundColor);
        pane.setBackgroundAt(i, backgroundColor);
    }
    

    You can also use getComponentAt as well, similarly:

    for (int i = 0; i < pane.getTabCount(); i++) {
        pane.getComponentAt(i).setForeground(foregroundColor);
        pane.getComponentAt(i).setBackground(backgroundColor);
    }
    

    The latter approach is more flexible--you can later do more complex things to all the components using code like this.

提交回复
热议问题