1 回答
TA贡献1817条经验 获得超14个赞
package com.baiduwork;
import java.awt.*;
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.JFrame;
//定义个Jtree继承框架。
public class Jtree extends JFrame {
private DefaultMutableTreeNode root, red, green, blue;
private JTree jtree1;
private JPanel jpanel1;
private JFrame frame;
Jtree() {
super();
initilize();
}
//初始化。
public void initilize() {
frame = new JFrame("Jtree");
root = new DefaultMutableTreeNode("Color");
red = new DefaultMutableTreeNode("red");
blue = new DefaultMutableTreeNode("green");
green = new DefaultMutableTreeNode("green");
root.add(red);
root.add(blue);
root.add(green);
jtree1 = new JTree(root);
jpanel1 = new JPanel();
JSplitPane jsplitpane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
jtree1, jpanel1);
jsplitpane.setOneTouchExpandable(true);
jsplitpane.setMinimumSize(new Dimension(100, 50));
frame.getContentPane().add(jsplitpane);
frame.setSize(600, 500);
frame.setLocation(50, 50);
frame.setVisible(true);
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new Jtree();
}
}
例子。
添加回答
举报