• Post Reply Bookmark Topic Watch Topic
  • New Topic

JPanel not always opaque by default ...

 
Ronald Wouters
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

when running some tests on my linux box (RHEL) the last couple of days I had trouble setting background colors of a simple JPanel. The colors did show up correctly running the crossplatform look on feel (javax.swing.plaf.metal.MetalLookAndFeel). The colors did NOT show up correctly running the system look and feel (com.sun.java.swing.plaf.gtk.GTKLookAndFeel).
After some troubleshooting I finally did a simple test to check the opaque property of a JPanel (full sourcecode below). The results were disturbing to me: using MetalLookAndFeel a JPanel is created opaque by default, using the GTKLookAndFeel a JPanel is NOT opaque by default ??!! Obviously this has some undesired effects for colors showing up or not.
Does anyone know why the opaqueness of a panel would need to be different under different look and feels ?
Anyone else observed this behaviour ?
Bottom line, if you want to make sure colors show up correctly, always set the opaque property even when you think it is not neccessary...

Regards, Ronald.

Here is the test source code, note the comments and run under linux/winxp to see the differences.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm moving this to our Swing forum because I think you will get a response there.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!