This discussion is archived
2 Replies Latest reply: Oct 2, 2012 3:54 AM by gimbal2 RSS

Swing and Nimbus Java Bug

965581 Newbie
Currently Being Moderated
I have a simple app with 2 frames and Nimbus for L&F. I'm running against this bug:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7169951

I can't vote on it (?) and it's low priority for some reason. However, when my second frame loads it's all messed up and the app crashes so it's a showstopper for me.

I've no clue where to look for a workaround or what I can do to prevent this. If the first frame is never opened it doesn't happen, but if it is opened, the app crashes when adding a panel with components to the second frame and setting it visible.

Please help me finding a workaround or solution for this problem. I can't just let Nimbus out.
  • 1. Re: Swing and Nimbus Java Bug
    965581 Newbie
    Currently Being Moderated
    The problem was caused by missing "defaultFont" key in UIDefaults. This key is needed by many UI delegates in Nimbus look and feel. Inspired by this commit:

    http://hg.netbeans.org/main/rev/19e15af84fe2

    I decided to change the font defaults via the ui manager. There I had a new problem and following the (non-accepted) solution as proposed by Arnon on this thread:

    http://stackoverflow.com/questions/949353/java-altering-ui-fonts-nimbus-doesnt-work

    And using inspection to get around the problem that Nimbus changed packages in JDK releases,

    I got to this workaround:

    try {
              for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
              if ("Nimbus".equals(info.getName())) {
              UIManager.setLookAndFeel(info.getClassName());
              UIManager.getDefaults().put("defaultFont", new Font(Font.SANS_SERIF, 0, 12));
              log.info("setting nimbus look and feel");
              }
              }
              } catch (Exception e) {
    //..
    }

    Now I can start developing.
  • 2. Re: Swing and Nimbus Java Bug
    gimbal2 Guru
    Currently Being Moderated
    Thanks for posting back, I'm sure you save someone the trouble of doing the same research you did. Please use \
     tags in the future to make code more clear and to stop the forum from trying to interpret it.                                                                                                                                                                                                                                                                                                                                                                                                                                        

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points