Swing, Pluggable Look & Feel

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:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes