0

I'm having a problem with the java look and feel.

I've set it to the Nimbus skin with the following code in my main method:

public class Main
{
    public static void main(String[] args)
    {
        try
        {
            boolean found = false;
            for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
            {               
                if ("Nimbus".equals(info.getName()))
                {
                    UIManager.setLookAndFeel(info.getClassName());
                    found = true;
                    break;
                }
            }

            if (!found) UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            UIManager.put("AuditoryCues.playList", UIManager.get("AuditoryCues.allAuditoryCues"));
        }
        catch (Exception e) {}

        Manager mngr = new Manager();
        mngr.setSize(1000, 600);
        Utils.centerWindow(mngr);
        mngr.setVisible(true);
    }
}

And it gives me this kind of windows:

enter image description here

As you can see, the JInternalFrames are correctly skinned but the main window is not!

How can I apply the theme to this window too?

Thanks.


Manager is a simple JFrame with the following code:

public class Manager extends JFrame
{
    public Manager()
    {
        initComponents();
    }

    private void initComponents()
    {
        setDefaultCloseOperation(3);
        setTitle("My window");
        setIconImage(ImageLoader.getIcon().getImage());

        // My components go here

        pack();
    }
}
Manitoba
  • 8,522
  • 11
  • 60
  • 122
  • When do you call the method which runs the code you've given? Make sure it's the first thing that happens in your program. – kentcdodds Apr 20 '12 at 13:44
  • I'm guessing the `Manager` is that main window. That's really weird they're giving different look and feels for the windows. Also, the JInternalFrames don't look like my Nimbus look-and-feels... I'm guessing you're on linux or something though. Without a real SSCCE(.org) I don't think I can help you any further... – kentcdodds Apr 20 '12 at 14:02
  • Well, Manager is the main window that is on the joined image. I'm running a custom Windows 7 distrib. Well, what else do you want to know? – Manitoba Apr 20 '12 at 14:10

3 Answers3

3
mKorbel
  • 109,525
  • 20
  • 134
  • 319
0

Well, I'm not sure what to do for you without a good SSCCE, but if you want an example of a method that always works for me you can take a look at Java-Helper on github. Specifically, look at the SwingHelper at this line. I'm adding the code below in order to be in compliance with some of the ground rules of stack overflow ;) Best of luck to you.

  /**
   * Sets the look and feel to the given type (like "Nimbus") Learn more here:
   * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
   *
   * @param lookAndFeel to set (like "Nimbus")
   */
  public static void setLookAndFeel(String lookAndFeel) {
    try {
      for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
        if ((info.getName()).equals(lookAndFeel)) {
          javax.swing.UIManager.setLookAndFeel(info.getClassName());
          break;
        }
      }
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
      java.util.logging.Logger.getLogger(SwingHelper.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
  }
kentcdodds
  • 27,113
  • 32
  • 108
  • 187
0

Just try switching on these two options before frames/dialogs creation:

JDialog.setDefaultLookAndFeelDecorated ( true );
JFrame.setDefaultLookAndFeelDecorated ( true );

This will allow JFrame/JDialog get their decoration from the LaF instead of system.

Mikle Garin
  • 10,083
  • 37
  • 59
  • I tried but nothing changed at all. I added the second line just before `Manager mngr = new Manager();` – Manitoba Apr 20 '12 at 17:55
  • 1
    I tried this with a few LaFs - it doesn't work only with Nimbus. As i could see from some topics Nimbus seems to use system decoration on Windows-type OS. Don't see any solutions to that though... – Mikle Garin Apr 20 '12 at 18:48