0

I have set the look and feel nimbus in my java application, but i dont know why the view is always different from one frame to other. in a frame I got perfectly good blue nimbus, and in other frame I got the grey one but that's not proper. and the other one was not displayed as using nimbus look and feel. here's the code that I use in main

try {
    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
            UIManager.setLookAndFeel(info.getClassName());
            break;
        }
    }
    } catch (Exception e) {
    // If Nimbus is not available, you can set the GUI to another look and feel.
}

I also import

import javax.swing.*;
import javax.swing.UIManager.LookAndFeelInfo;

I hope somebody can help me, thank you.

unknown
  • 4,859
  • 10
  • 44
  • 62
charcoalite
  • 43
  • 1
  • 2
  • 10
  • 1
    Possibly related: http://stackoverflow.com/questions/7612592/jframe-and-nimbus-look-and-feel – assylias Apr 06 '12 at 20:10
  • 1
    Does it work correctly if you run the app with `java -Dswing.defaultlaf=javax.swing.plaf.nimbus.NimbusLookAndFeel MyApp` (see: http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/nimbus.html) – ulmangt Apr 06 '12 at 20:11

1 Answers1

5

When you switch from one Look and feel to another, you must make sure to invoke the SwingUtilities#updateComponentTreeUI method once for each top-level container. Also, if you store UI components which are not part of any visible UI/top-level container, you will have to update those as well.

For example if your second panel was already created when you switch look-and-feel, make sure to update it as well.

There is, like for almost anything in Swing, a rather good tutorial available

Robin
  • 36,233
  • 5
  • 47
  • 99