This page looks plain and unstyled because you're using a non-standard compliant browser. To see it in its best form, please upgrade to a browser that supports web standards. It's free and painless.

Robert Marcano's blog
Get Firefox Use OpenOffice.org hacker emblem

JTabbedPane background on Windows XP

robert | 06 July, 2005 16:13

I am not a fan of the usage of notebook like widgets because I think that they tend to make the application interface cluttered, I prefer wizard like structures, but sometimes they are the best solution available. In Java this kind of component is called a JTabbedPane

For some reason when looking a JTabbedPane with the Windows look and feel on Windows XP (Luna theme), a small anoyance is revealed: JPanel components on the JTabbedPane are opaque thus hiding the tabbed pane default background, like this:

JTabbedPane with the wrong background on Windows XP

To solve this remember to set your JPanels and other components like radio buttons and checkboxes non opaque:

panel.setOpaque(false);

and you will get a nicer tabbed pane

JTabbedPane with the correct background on Windows XP

Update 07/06/2005: I forgot to tell that this only works with JSE 5.0 because the Windows Look and Feel on previous releases did not implemented the correct JTabbedPane background

Update 07/08/2005: This probably is a bug in the Sun implementation as said by one of the commentators, but I think they will not change that because JPanels on the Windows L&F has been always opaque. My solution involves the usage of a custom utility method that traverse the components tree and change the opacity for the panels when the Windows L&F is active.

Comments

Re: JTabbedPane background on Windows XP

Swapnonil Mukherjee | 07/07/2005, 18:53

A lot of people have noticed this discrepancy and this is indeed a bug.

Ideally we should not be required to take a panel and each component on it, and set it to non-opaque.

This is so bloody awful.

What about background color?

Justin | 13/07/2005, 23:36

The above opacity hint is helpful. However, I'm experiencing problems setting the background color (JTabbedPane.setBackgroundAt(int index, Color color). I'm only affected when XP themes are enabled and the UIManager is set to use the system's look and feel. I believe it's a bug in the JDK/JRE.

Using setBackgroundAt works flawlessly in any non-XP OS. It appears to do nothing with the XP theme, though. Has anybody else encountered this?

See Bug ID: 5032785

Robert | 13/07/2005, 23:46

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5032785

It is closed as "Not Fixed"

XP related bug

Jonathan | 31/08/2007, 07:52

Thanks for the hint about opacity. I'd tried setting it to "true", thinking the background wasn't being painted, but hadn't tried false!

I'd just found a reference to the bug above: the tab background colour is wrong when using Windows XP. This method is a perfect work around for my purposes, but it's still an unfortunate bug.

Add comment

 authimage
 
Valid XHTML 1.0 Strict and CSS.
Copyright 2003-2007 Robert Marcano. All Rights Reserved
Powered by LifeType
Original Design by Book of Styles