Sun's JRE provides the following L & FS:
CrossPlatformLookAndFeel
-This is the "Java L & F" (also called "Metal") that looks the same on all platforms. It is part of the Java API (javax.swing.plaf.metal
) And is the default that will be used if you do nothing in your code to set a different L & F.
SystemLookAndFeel
-Here, the application uses the L & F that is native to the system it is running on. the system L & F is determined at runtime, where the application asks the system to return the name of the appropriate L & F.
- Synth-the basis for creating your own look and feel with an XML file.
- Multiplexing-a way to have the UI Methods delegate to a number of different look and feel implementations at the same time.
In summary, when you useSystemLookAndFeel
, This is what you will see:
Platform |
Look and Feel |
Solaris, Linux with GTK + 2.2 or later |
GTK + |
Other Solaris, Linux |
Motif |
IBM Unix |
IBM * |
HP UX |
HP * |
Classic windows |
Windows |
Windows XP |
Windows XP |
Windows Vista |
Windows Vista |
Macintosh |
Macintosh * |
In the API you will see four L & F packages:
javax.swing.plaf.basic
-Basic UI delegates to be extended when creating a custom L & F
javax.swing.plaf.metal
-The Java L & F, also known as the crossplatform L & F ("Metal" was the sun project name for this L & F) The current default "theme" (discussed below) for this L & F is "ocean, so this is often referred to as the ocean L & F.
javax.swing.plaf.multi
-A multiplexing look and feel that allows the UI methods to delegate to a number of look and feel implementations at the same time. it can be used to augment the behavior of a particle look and feel, for example with a L & F that provides audio cues on top of the Windows look and feel. this is a way of creating a handicapped-accessible look and feel.
javax.swing.plaf.synth
-An easily configured L & F using XML files (discussed in the next section of this lesson)
To programatically specify a L & F, useUIManager.setLookAndFeel()
Method with the fully qualified name of the appropriate subclassLookAndFeel
As its argument. For example, the bold Code in the following snippet makes the program use the cross-platform Java L & F:
public static void main(String[] args) { try { // Set cross-platform Java L&F (also called "Metal") UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName()); } catch (UnsupportedLookAndFeelException e) { // handle exception } catch (ClassNotFoundException e) { // handle exception } catch (InstantiationException e) { // handle exception } catch (IllegalAccessException e) { // handle exception } new SwingApplication(); //Create and show the GUI.}
Alternatively, this Code makes the program use the system L & F:
public static void main(String[] args) { try { // Set System L&F UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName()); } catch (UnsupportedLookAndFeelException e) { // handle exception } catch (ClassNotFoundException e) { // handle exception } catch (InstantiationException e) { // handle exception } catch (IllegalAccessException e) { // handle exception } new SwingApplication(); //Create and show the GUI.}
You can also use the actual class name of a look and feel as the argumentUIManager.setLookAndFeel()
. For example,
// Set cross-platform Java L&F (also called "Metal")UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
Or
// Set Motif L&F on any platformUIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
From: http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html