How do I change the color of the selected tab on a JTabbedPane?
Created May 4, 2012
John Zukowski
All you need to do is set the "TabbedPane.selected" property to the desired color in the UIManager. The following program demonstrates this capability.
import java.awt.*; import javax.swing.*; public class TabSample { static void addIt (JTabbedPane tabbedPane, String text) { JLabel label = new JLabel(text); JButton button = new JButton(text); JPanel panel = new JPanel(); panel.add(label); panel.add(button); tabbedPane.addTab(text, panel); } public static void main (String args[]) { JFrame f = new JFrame("JTabbedPane Sample"); Container content = f.getContentPane(); UIManager.put("TabbedPane.selected", Color.white); JTabbedPane tabbedPane = new JTabbedPane(); addIt(tabbedPane, "Tab One"); addIt(tabbedPane, "Tab Two"); addIt(tabbedPane, "Tab Three"); addIt(tabbedPane, "Tab Four"); addIt(tabbedPane, "Tab Five"); content.add(tabbedPane, BorderLayout.CENTER); f.setSize (300, 200); f.setVisible (true); } }