⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testtree4.java

📁 java swing 开发代码
💻 JAVA
字号:
// TestTree4.java// Another test to see how we can build a tree and customize its icons.// This example does not affect the icons of other trees.//package	jswing.ch17;import java.awt.*;import java.util.*;import javax.swing.*;import javax.swing.tree.*;public class TestTree4 extends JFrame {  JTree tree1, tree2;  DefaultTreeModel treeModel;  public TestTree4() {    super("Custom Icon Example");    setSize(350, 450);    setDefaultCloseOperation(EXIT_ON_CLOSE);    // Build the hierarchy of containers & objects    String[] schoolyard = {"School", "Playground", "Parking Lot", "Field"};    String[] mainstreet = {"Grocery", "Shoe Shop", "Five & Dime",                            "Post Office"};    String[] highway = {"Gas Station", "Convenience Store"};    String[] housing = {"Victorian_blue", "Faux Colonial",                         "Victorian_white"};    String[] housing2 = {"Mission", "Ranch", "Condo"};    Hashtable homeHash = new Hashtable();    homeHash.put("Residential 1", housing);    homeHash.put("Residential 2", housing2);    Hashtable cityHash = new Hashtable();    cityHash.put("School grounds", schoolyard);    cityHash.put("Downtown", mainstreet);    cityHash.put("Highway", highway);    cityHash.put("Housing", homeHash);    Hashtable worldHash = new Hashtable();    worldHash.put("My First VRML World", cityHash);        // Build our tree out of our big hashtable    tree1 = new JTree(worldHash);    tree2 = new JTree(worldHash);    DefaultTreeCellRenderer renderer =       (DefaultTreeCellRenderer)tree2.getCellRenderer();    renderer.setClosedIcon(new ImageIcon("door.closed.gif"));    renderer.setOpenIcon(new ImageIcon("door.open.gif"));    renderer.setLeafIcon(new ImageIcon("world.gif"));    JSplitPane pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,      tree1, tree2);    getContentPane().add(pane, BorderLayout.CENTER);  }  public static void main(String args[]) {    TestTree4 tt = new TestTree4();    tt.setVisible(true);  }}

⌨️ 快捷键说明

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