Swing, Pluggable Look & Feel

With Swing, you can easily change the Look & Feel (L&F) at run time to match one of the L&F implementations in your system. This program contains strings identifying three different L&F implementations contained in Swing 1.0.3 for Win95. Compile and run the program to see PL&F in action. The key statements are:

 plafClassName = motif;//or metal or windows  UIManager.setLookAndFeel(plafClassName);SwingUtilities.updateComponentTreeUI(thisPlafPanel);  

To change the L&F, assign a different L&F string to plafClassName and recompile the program. To upgrade the program to change the L&F at run time, assign a different L&F sting to plafClassName and execute the other two key statements. This code was tested using JDK1.1.6 and Swing 1.0.3 under Win95.

 import java.awt.event.*;import java.awt.*;import com.sun.java.swing.*;import java.util.*;public class PlafStandalone01 extends JFrame {	//Three L&F implementations contained in Swing 1.0.3	// for Win95 follow.	String metal = 		"com.sun.java.swing.plaf.metal.MetalLookAndFeel";	String motif = 			"com.sun.java.swing.plaf.motif.MotifLookAndFeel";	String windows = 		"com.sun.java.swing.plaf.windows.WindowsLookAndFeel";	String plafClassName;//store the L&F string here	PlafStandalone01 thisPlafPanel = this;//ref to this obj	//-----------------------------------------------------//  	public PlafStandalone01(){//constructor		getContentPane().setLayout(new FlowLayout());		getContentPane().add(new JButton("JButton"));		getContentPane().add(new JToggleButton(				"JToggleButton"));		setTitle("Pluggable Look & Feel");		setBounds(30,300,350,150);    		//Set the Look and Feel by enabling one of these		//plafClassName = motif;		//plafClassName = metal;		plafClassName = windows;		try{			UIManager.setLookAndFeel(plafClassName);		}catch(Exception ex){System.out.println(ex);}      		//Cause the L&F to become visible.		SwingUtilities.updateComponentTreeUI(thisPlafPanel);		this.setVisible(true);	}//end constructor	//=====================================================//	public static void main(String[] args){		new PlafStandalone01();	}//end main()}//end class PlafStandalone01
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS