[Java Swing] How to set look & feel

Source: Internet
Author: User
Tags gtk hp ux

Sun's JRE provides the following L & FS:

  1. 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.
  2.  

  3. 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.
  4.  

  5. Synth-the basis for creating your own look and feel with an XML file.
  6.  

  7. 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 subclassLookAndFeelAs 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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.