EarthWeb
Developer.com
Site
windows 2000
visual c++
java
visual basic
javascripts
recommend it
 
Book
thinking in java
 
Interact
forum
guest book
jobs
jokes
what's new

share code
 
Resource
add resource
modify resource
new resource
 

[Internet Jobs]
-----
Java by E-mail:

Get the weekly e-mail highlights on Java!
-----

-

Change the look and feel at any time.


Author: Zafir Anjum

Change the look and feel at any time by calling UIManager.setLookAndFeel(). Since any previous component will already have the previous we also need to update them so that they use the new look and feel. We use the function SwingUtilities.updateComponentTreeUI(frame) to do that.


try {
	UIManager.setLookAndFeel(new com.sun.java.swing.plaf.motif.MotifLookAndFeel());
}
catch (Exception e) {}
SwingUtilities.updateComponentTreeUI(tree.getRootPane());

In the above case we are setting up the Motif L&F. Note that the desired L&F should be installed for this to work.

Here's a sample program.


import java.awt.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;


public class Tree
{
	static JTree tree ;
	
	public static void main(String[] args)
	{
		JFrame frame = new JFrame("Tree");
		frame.addWindowListener( new WindowAdapter() {
			public void windowClosing(WindowEvent e)
			{
				Window win = e.getWindow();
				win.setVisible(false);
				win.dispose();
				System.exit(0);
			}
		} );
		
		frame.getContentPane().setLayout( new BorderLayout() );
		
		

		tree = new JTree();
	
		JScrollPane sp = new JScrollPane( tree );
		frame.getContentPane().add( sp, "Center" );

		JButton btn = new JButton( "Test");
		btn.addActionListener( new ActionListener() {
					public void actionPerformed( ActionEvent e )
					{
						test();
					}
				} );
		frame.getContentPane().add( btn, "South" );
		frame.pack();
		frame.show();
	}
	

	static boolean angled = true;
	static void test()
	{
		try {
			UIManager.setLookAndFeel(new com.sun.java.swing.plaf.motif.MotifLookAndFeel());
		}
		catch (Exception e) {}
		SwingUtilities.updateComponentTreeUI(tree.getRootPane());
		tree.repaint();
	}
}



Posted On: 21-Feb-1999

internet.commerce
Partner With Us
Logo Design
Dental Insurance
Online Universities
Computer Deals
KVM over IP
Nutrisystem
Phone Cards
Promotional Items
Promotional Products
Promote Your Website
Promos and Premiums
Laptops
Free Business Cards
Best Price



Acceptable Use Policy

JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers