Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Java
Expertise: Intermediate
Oct 27, 1998



Application Security Testing: An Integral Part of DevOps

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  
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 = 
	String motif = 
	String windows = 

	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(
		setTitle("Pluggable Look & Feel");
		//Set the Look and Feel by enabling one of these
		//plafClassName = motif;
		//plafClassName = metal;
		plafClassName = windows;
		}catch(Exception ex){System.out.println(ex);}
		//Cause the L&F to become visible.
	}//end constructor

	public static void main(String[] args){
		new PlafStandalone01();
	}//end main()
}//end class PlafStandalone01
Richard G.
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date