主题:怎样运用jTree实现导航啊!? 急!!!
anon
[专家分:0] 发布于 2007-02-21 11:15:00
帮我解决这个问题吧!
困扰我很久了![em10]
回复列表 (共3个回复)
沙发
yexin218 [专家分:4070] 发布于 2007-02-21 22:34:00
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
public class TreeDemo2
{
public TreeDemo2()
{
JFrame f = new JFrame("TreeDemo");
Container contentPane = f.getContentPane();
DefaultMutableTreeNode root = new DefaultMutableTreeNode("档案总管");
DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("文件夹");
DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("我的电脑");
DefaultMutableTreeNode node3 = new DefaultMutableTreeNode("我的最爱");
DefaultMutableTreeNode node4 = new DefaultMutableTreeNode("Readme");
root.add(node1);
root.add(node2);
root.add(node3);
root.add(node4);
DefaultMutableTreeNode leafnode = new DefaultMutableTreeNode("公司文件");
node1.add(leafnode);
leafnode = new DefaultMutableTreeNode("个人信件");
node1.add(leafnode);
leafnode = new DefaultMutableTreeNode("私人文件");
node1.add(leafnode);
leafnode = new DefaultMutableTreeNode("本地磁盘(C:)");
node2.add(leafnode);
leafnode = new DefaultMutableTreeNode("本地磁盘(D:)");
node2.add(leafnode);
leafnode = new DefaultMutableTreeNode("本地磁盘(E:)");
node2.add(leafnode);
DefaultMutableTreeNode node31 = new DefaultMutableTreeNode("网站列表");
node3.add(node31);
leafnode = new DefaultMutableTreeNode("sina");
node31.add(leafnode);
leafnode = new DefaultMutableTreeNode("yahoo");
node31.add(leafnode);
leafnode = new DefaultMutableTreeNode("163");
node31.add(leafnode);
JTree tree = new JTree(root);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setViewportView(tree);
contentPane.add(scrollPane);
f.pack();
f.setVisible(true);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public static void main(String args[]) {
new TreeDemo2();
}
}
板凳
anon [专家分:0] 发布于 2007-02-22 15:33:00
非常谢谢你的指点!!!
祝你新年快乐!
呵呵,我是初学者,有问题我还会问你的哦!
3 楼
zcs179895723 [专家分:330] 发布于 2008-07-22 21:02:00
请问应该加一个怎么样得事件响应呢。当我点击不同的叶子节点时显示相应的名称。
我来回复