Java programming course: 18.4 Setting the look and feel


Setting the look and feel

AdministratorFrame constructor, immediately after the call to super():  

// Set to native look & feel
try {
    UIManager.setLookAndFeel
			(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
    e.printStackTrace();
    // If unable just carry on with default look & feel
}
 
  • UIManager is a class that manages look & feels. It contains the static method setLookAndFeel() that takes as a String argument the name of the class that controls the look & feel you want
  • The argument being passed is the String returned by another static method of UIManager called getSystemLookAndFeelClassName(). This returns the name of the class for the platform on which it is executing, if there is one, or the default look & feel otherwise
  • The setLookAndFeel() method can potentially throw one of several different exceptions (see the Javadoc API), so for simplicity the code above catches the superclass of all of these, being Exception
  • If an exception is thrown, it is hoped that the display will still render using the default look & feel, so the exception details are sent to the console and the application will continue anyway

Here is how it looks on the Windows platform:

Windows look and feel

The only major topic left to cover is that of storing the data in a file or database, which is known as persistence. This will be covered in the next series of lessons.



Print
×
Stay Informed

When you subscribe, we will send you an e-mail whenever there are new updates on the site.

Related Posts

 

Comments

No comments made yet. Be the first to submit a comment
Friday, 05 June 2026

Captcha Image