It's not a secret anymore!*
The moose likes Swing / AWT / SWT and the fly likes Weird System Look and Feel behaviour Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Weird System Look and Feel behaviour" Watch "Weird System Look and Feel behaviour" New topic
Author

Weird System Look and Feel behaviour

Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

I've written a handy method to frame a panel so I can test how it looks, but what I'm finding is that when I try to call it, on the first window that comes up, the JButtons don't have the correct look and feel. Subsequent windows are OK.

I thought maybe the look and feel wasn't loading fully before the frame was displayed, but I put a Thread.sleep in there to give it time, and that didn't help.

Also tried Nimbus look and feel, and get the same problem.

Taking the setLookAndFeel method out all together results in the default Metal displaying OK. It looks like the first window's buttons have no look and feel set at all.

By the way, I also tried this on my laptop (windows XP) and by compiling from the command prompt, and it still happens, so you should be able to reproduce this.



Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

Gah... I've sort-of figured it out. Nothing to do with threads or timing or final variables. It seems that if I create a JButton before the Look and Feel is set, it doesn't get displayed properly. If I create the buttons *after* the first panel has been framed (and the look and feel set), they do.

So in the following code, Button 1 is displayed incorrectly, but Button 2 is correct.



If I change the main to the following, neither displays correctly.

If I set the Look and Feel in the main method instead, it works OK.

But I want to keep the framePanel method in a separate utility class... seems I have no alternative but to take out the look-and-feel setting and do it before I create any components?

I was under the impression you could set the look and feel at any time before you make components visible, but is would seem not.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Weird System Look and Feel behaviour
 
Similar Threads
JProgressBar in Napkin look and feel is not working
Why aren't my components wrapping?
Graphs.
Stuck on setVisible()
Metal Look and Feel of JFrame on Windows XP