JTabbedPane in Windows XP

In Java 1.5, Sun implemented the Windows XP look and feel for the JTabbedPane. Learn how to modify your JTabbedPane to take advantage of the new Windows XP look and feel.

When creating JTabbedPane, you add a JPanel to each tabbed pane. The JPanel contains the controls in the tab. The following image shows a sample of the JTabbedPane running in Java 1.5 on Windows XP.

You'll notice that the tabs have the XP look and feel, but the content area is a solid color. In Windows XP, the content area of the tab should be a gradient background. In order to get the gradient background to display, you need to modify the JPanel that is added to the JTabbedPane. By default, the JPanel is opaque. You will need to set the JPanel's opaque flag to false so the gradient background will show through.

//Create the panel for a tab
JPanel panel1 = new JPanel(new FlowLayout());
Here's the results of setting the opaque flag on the JPanel.

The background of the tab shows the gradient. For non-rectangular controls such as radio buttons or check boxes, you will need to set the opaque flag to false for each of the radio buttons.

JRadioButton radioButton = new JRadioButton("Radio 1");
Finally, the tab and the controls in it have the complete Windows XP look and feel.


Post a Comment