objecttree.java

来自「java swing 开发代码」· Java 代码 · 共 44 行

JAVA
44
字号
// ObjectTree.java// A simple test to see how we can build a tree and populate it.  This version// builds the tree from hashtables.//package	jswing.ch17;import java.awt.*;import javax.swing.*;import java.util.*;public class ObjectTree extends JFrame {  JTree tree;  String[][] sampleData = {    {"Amy"}, {"Brandon", "Bailey"},    {"Jodi"}, {"Trent", "Garrett", "Paige", "Dylan"},    {"Donn"}, {"Nancy", "Donald", "Phyllis", "John", "Pat"},     {"Ron"}, {"Linda", "Mark", "Lois", "Marvin"}  };  public ObjectTree() {    super("Hashtable Test");    setSize(400, 300);    setDefaultCloseOperation(EXIT_ON_CLOSE);  }  public void init() {    Hashtable h = new Hashtable();    // Build up the hashtable using every other entry in the String[][] as a key    // followed by a String[]"value."    for (int i = 0; i < sampleData.length; i+=2) {      h.put(sampleData[i][0], sampleData[i + 1]);    }    tree = new JTree(h);    getContentPane().add(tree, BorderLayout.CENTER);  }  public static void main(String args[]) {    ObjectTree tt = new ObjectTree();    tt.init();    tt.setVisible(true);  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?