Controlling Color in Java Tabbed Pane

后端 未结 3 752
夕颜
夕颜 2020-12-17 01:21

I have been going nuts trying to figure this out.

I am trying to elimenate a light blue background that appears in a JTabbedPane. I\'ve tried everything and nothin

3条回答
  •  星月不相逢
    2020-12-17 01:37

    I used your example code, and what worked for me was moving the calls to UIManager.put() to a point where they would be executed before the JTabbedPane constructor was executed.

    public class Main extends JFrame {
        JTabbedPane tab;
    
        public Main() {
           // ... other stuff
           UIManager.put("TabbedPane.contentAreaColor ",ColorUIResource.GREEN);
           UIManager.put("TabbedPane.selected",ColorUIResource.GREEN);
           UIManager.put("TabbedPane.background",ColorUIResource.GREEN);
           UIManager.put("TabbedPane.shadow",ColorUIResource.GREEN);
    
           // now construct the tabbed pane
           tab=new JTabbedPane();
    
           // ... other stuff
     }
    

    There's also some other properties available (for the Metal L&F, at least):

    UIManager.put("TabbedPane.borderColor", Color.RED);
    UIManager.put("TabbedPane.darkShadow", ColorUIResource.RED);
    UIManager.put("TabbedPane.light", ColorUIResource.RED);
    UIManager.put("TabbedPane.highlight", ColorUIResource.RED);
    UIManager.put("TabbedPane.focus", ColorUIResource.RED);
    UIManager.put("TabbedPane.unselectedBackground", ColorUIResource.RED);
    UIManager.put("TabbedPane.selectHighlight", ColorUIResource.RED);
    UIManager.put("TabbedPane.tabAreaBackground", ColorUIResource.RED);
    UIManager.put("TabbedPane.borderHightlightColor", ColorUIResource.RED);
    

    These let you control most of the colours in the tab area.

    I found with these settings there was still a very small blue-ish grey border around the content. I have searched for how to set this colour to no avail. The only solution I could find to get rid of this was:

    UIManager.put("TabbedPane.contentBorderInsets", new Insets(0, 0, 0, 0));
    

    Which is a sub-optimal solution.

提交回复
热议问题