Friday, February 1, 2013

Java - Swing's Nimbus Look & Feel

Since Java SE 6 Update 10, Java has had an updated interface called Nimbus. Comparison pictures are below. 

All I needed to do to use it was add this import to the top of the .java file with my main() method:
import javax.swing.UIManager.*;

public static void main(String[] args) {
try {
    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
            UIManager.setLookAndFeel(info.getClassName());
            break;
        }
    }
} catch (Exception e) {
    // If Nimbus is not available, fall back to cross-platform
    try {
        UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    } catch (Exception ex) {
        // not worth my time
    }
}
new Controller();
}


Default

Nimbus
Note: This blog post says it is slightly slower than the default: http://www.pushing-pixels.org/2008/06/17/lightbeam-measuring-performance-of-swing-look-and-feels.html

No comments:

Post a Comment