Author: Zafir Anjum
Select a L&F that matches the look and feel of the native OS.
try {
UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
}
catch (Exception e) {}
Note that the native 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() );
try {
UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
}
catch (Exception e) {}
tree = new JTree();
JScrollPane sp = new JScrollPane( tree );
frame.getContentPane().add( sp, "Center" );
frame.pack();
frame.show();
}
}
Posted On: 21-Feb-1999