Java Champion / JavaOne Rockstar Adam Bien (adam-bien.com) is a self-employed consultant, lecturer, software architect, developer, and author in the enterprise Java sector. He is also the author of several books and articles on Java and Java EE technology, as well as distributed Java programming. adam has posted 59 posts at DZone. View Full User Profile

Swing Looks ...Great (Part III Nimbus)

12.01.2010
| 8449 views |
  • submit to reddit

Nimbus comes already with JDK 1.6.

Nimbus doesn't have to be installed, it is shipped with JDK 1.6. You only have to activate it. There is a hacky (because of reflection) but robust way to activate that. This complex approach is needed, because Nimbus was introduced with JDK 1.6u10 and was not available before.

try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (UnsupportedLookAndFeelException e) {
// handle exception
} catch (ClassNotFoundException e) {
// handle exception
} catch (InstantiationException e) {
// handle exception
} catch (IllegalAccessException e) {
// handle exception
}

[Code Snippet from:http://download.oracle.com/javase/6/docs/technotes/guides/jweb/otherFeatures/nimbus_laf.html]
The command line option -Dswing.defaultlaf=com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel can be used as well.With NetBeans you can create a Nimbus mock-up in minutes (actually seconds).

From http://www.adam-bien.com/roller/abien/entry/swing_looks_great_part_iii

Published at DZone with permission of its author, adam bien.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)