banner

Look and Feel

Optional Reading

We will be using the Creating a GUI with JFC/Swing tutorial from Sun as a Reference source. You are not required to read the entire tutorial, I suggest you skim through it though to use as a supplement to what I give you here.

Look and Feel

One of the interesting features of Swing is the notion of changeable look and feels. The look and feel is the visual presentation of components on the screen, and how they react to user input.

Java currently supports several look and feels:

In general, you can only see Windows based look and feel on Windows platforms, GTK on Linux and Solaris, and Mac on Macs. Java, Synth and Motif (blah!) work on all platforms.

When you run Java, you get the Java look and feel by default. You can set the look and feel to that of the native OS you are using on fairly easily. The following example illustrates the preferred way of setting the look and feel to match that of the native platform:

Use the following code:

try {
  UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e) {
   System.err.println(“Could not load LookAndFeel”);
}

This should be placed in the main() method of your primary class.

Download and open the Netbeans project lookandfeel. In this project, you should be able to see some examples of setting different look and feels on a Windows platform.

Windows Look and Feel

Motif Look and Feel

Java Look and Feel

 


g src="../Images/lookandfeel-3.gif" alt="Java Look and Feel" width="377" height="177" />