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!
-----

-

Metal L&F - Adding angled and horizontal lines between nodes


Author: Zafir Anjum

Add angled lines between nodes (as in Windows explorer) or add horizontal lines separating the nodes. Specific to Metal look and feel.

By default, under the Metal (Java) look and feel, no lines are drawn to connect or group the nodes. Drawing of the lines are drawn by client property of the JComponent - "JTree.lineStyle".

The first image shows the default with no lines ("None"), the second image shows the "Angled" lineStyle and the third shows the "Horizontal" lineStyle.

Default Angled Horizontal

Here's the code snippet that changes the property.


tree.putClientProperty( "JTree.lineStyle", "Angled" );
tree.repaint();

And here's a complete sample.


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("Table");
		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()
	{
		if( angled )
			tree.putClientProperty( "JTree.lineStyle", "Angled" );
		else
			tree.putClientProperty( "JTree.lineStyle", "Horizontal" );
		
		angled = !angled;

		tree.repaint();
	}
	
}

Posted On: 18-Feb-1999

internet.commerce



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