How to set the look and feel for a Swing application?
The Java Development Kit contains a few look and feel classes (i.e. subclasses of the LookAndFeel class)
com.sun.java.swing.plaf.gtk.GTKLookAndFeel
javax.swing.plaf.metal.MetalLookAndFeel
com.sun.java.swing.plaf.windows.WindowsLookAndFeel
com.sun.java.swing.plaf.motif.MotifLookAndFeel
You can set any of these by calling the setLookAndFeel() method of the UIManager
1 2 3 4 5 6 7 8 9 10 11 12 |
public static void main(String[] args) { try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel"); } catch (Exception ex) { //Just print stacktrace here since it's an example. ex.printStackTrace(); } SwingUtilities.invokeLater(new Runnable() { public void run() { createTheGUIComponents(); } }); } |
If you want the application to adjust to the platform it is currently running on, you can specify that the look and feel for the current system should be used:
1 |
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |