change active tab color in JTabbedPane

user3363537 picture user3363537 · May 2, 2014 · Viewed 10.5k times · Source

How can I change the color of tab when is selected ? and its border ? in this case its Arbitros tab which is blue, how can i change this ? I'm using JTabbedPane inside JFrame I found this but its not working UIManager.put("TabbedPane.selected", Color.white); what am I doing wrong ?

public VentanaPrincipal_vista() {

    super("Ventana Principal");

    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setSize(1000, 500);
    this.setResizable(false);
    this.setUndecorated(true);
    this.setBackground(Color.BLUE);
    // add tabbedPane and tabs .

    tabs = new JTabbedPane();
    tabs.setBackground(new Color(83, 83, 83));
    tabs.setForeground(new Color(255, 255, 255));
    tabs.setBorder(null);
    UIManager.put("TabbedPane.selected", Color.white);
    this.add(tabs);

    menuBar = new BGMenuBar();
    menuBar.setColor(new Color(83, 83, 83));
    this.setJMenuBar(menuBar);

    menu = new JMenu("File");
    menu.setForeground(Color.white);
    menuBar.add(menu);

    close = new JMenuItem("Close");

    menu.add(close);
    close.addActionListener(this);
    close.setBackground(new Color(83, 83, 83));
    close.setForeground(new Color(255, 255, 255));

    op1 = new JMenuItem("option 1");
    op1.setBackground(new Color(83, 83, 83));
    op1.setForeground(new Color(255, 255, 255));

    menu.add(op1);

    this.setLocationRelativeTo(null);
    this.setVisible(true);

}// end of constructor

enter image description here

Answer

Dip686 picture Dip686 · Jun 18, 2017

for me,the below solution worked, I just set the UImanager's TabbedPane.selected color property before creation of JTabbedPane object.

 UIManager.put("TabbedPane.selected", Color.red);

      tabbedPane = new JTabbedPane();

Refer this link, i'm sure it will work for you too.

http://esus.com/changing-the-color-of-the-selected-tab-of-a-jtabbedpane/