import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
public class SimpleTree
{ public static void main(String[] args)
{ JFrame frame = new SimpleTreeFrame();
frame.show();
}
}
class SimpleTreeFrame extends JFrame
{ public SimpleTreeFrame()
{ setTitle("SimpleTree");
setSize(300, 200);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ System.exit(0);
}
} );
// set up tree model data
DefaultMutableTreeNode root
= new DefaultMutableTreeNode("World");
DefaultMutableTreeNode country
= new DefaultMutableTreeNode("USA");
root.add(country);
DefaultMutableTreeNode state
= new DefaultMutableTreeNode("California");
country.add(state);
DefaultMutableTreeNode city
= new DefaultMutableTreeNode("San Jose");
state.add(city);
city = new DefaultMutableTreeNode("Cupertino");
state.add(city);
state = new DefaultMutableTreeNode("Michigan");
country.add(state);
city = new DefaultMutableTreeNode("Ann Arbor");
state.add(city);
country = new DefaultMutableTreeNode("INDIA");
root.add(country);
state = new DefaultMutableTreeNode("TamilNadu");
country.add(state);
city = new DefaultMutableTreeNode("Chennai");
state.add(city);
state = new DefaultMutableTreeNode("Karnataka");
country.add(state);
city = new DefaultMutableTreeNode("Bangalore");
state.add(city);
state = new DefaultMutableTreeNode("West Bengal");
country.add(state);
city = new DefaultMutableTreeNode("Kolkatta");
state.add(city);
// construct tree and put it in a scroll pane
JTree tree = new JTree(root);
Container contentPane = getContentPane();
contentPane.add(new JScrollPane(tree));
}
}
Subscribe to:
Post Comments (Atom)
Popular Posts
-
Hi folks, I got a chance to work with JSF, it was an interesting requirement. Its about a custom component which would be of more use to ...
-
Hi Folks, I would like to share my another POC task in JSF with you all. "Primefaces Dropdown with Pagination & Filter "...
-
We shall create temp table in mysql using the sql script CREATE TEMPORARY TABLE testraghu(name VARCHAR(50) , phone VARCHAR(50)) Let us se...
-
Hi all, i would like to share a simple example of storing haspmap in mysql db. In order to store object into your db, the field type must ...
No comments:
Post a Comment