Came across something interesting today while setting look and feels in my Java Application in Windows.

Basically i was trying to set the JGoodies Look & Feels and noticed a few weird things happening. I have 2 JFrames in my application, one is the login screen, the other is the main app screen. After setting the look and feel correctly in the main class in my app, i then initialised the two JFrames and setDefaultLookAndFeelDecorated(true); Then upon launching the look and feel decorated the 2nd window (app), but not the first (main), so i switched the code around and initialised the main app frame first and the login second.. and now it was decorating the login screen but not the main app.

This is actually the first time i’ve seen this happen before, but it’s kind of also the first time I’ve played with another look and feel that’s not native to the computer the app is running on. Anyway, this little problem was resolved by performing a setDefaultLookAndFeelDecorated(true); on the JFrame class BEFORE intialising all my JFrames, now everything looks normal.

A bit of a weird one…

2 thoughts on “Interesting Bug Maybe..

  1. Probably a timing issue of changing the look and feel. I normally set it very first thing in the main method. Basically each component you create will attempt to install a UI delegate on itself and use the currently initialized look and feel. If the first frame is created before you change the look and feel, you get the behavior you mentioned. When you change the look and feel on the fly you normally do something like this:

    UIManager.setLookAndFeel(lnfName);
    SwingUtilities.updateComponentTreeUI(frame);

    The SwingUtilities line must be called for each frame. This is because the method walks the tree of components in the frame and installs new UI delegates on each.

Comments are closed.