/** * @version 1.00 2002-06-30 * @author Ismael Santos - baseado no livro CoreJava 2 */ 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); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // set up tree model data // 1 - Subarvore Mundo - World DefaultMutableTreeNode root = new DefaultMutableTreeNode("World"); // 1 - 1 - Subarvore Pais - USA DefaultMutableTreeNode country = new DefaultMutableTreeNode("USA"); root.add(country); // 1 - 1 - 1 - Subarvore Estado - California DefaultMutableTreeNode state = new DefaultMutableTreeNode("California"); country.add(state); DefaultMutableTreeNode city = new DefaultMutableTreeNode("San Jose"); state.add(city); city = new DefaultMutableTreeNode("Cupertino"); state.add(city); // 1 - 1 - 2 - Subarvore Estado - Michigan state = new DefaultMutableTreeNode("Michigan"); country.add(state); city = new DefaultMutableTreeNode("Ann Arbor"); state.add(city); // 1 - 2 - Subarvore Pais - Alemanha country = new DefaultMutableTreeNode("Germany"); root.add(country); state = new DefaultMutableTreeNode("Schleswig-Holstein"); country.add(state); city = new DefaultMutableTreeNode("Kiel"); 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)); } }