美好的一天
我试图在jtree的节点和它的jframe之间建立链接 是左边的树,论坛将显示在右边 这是一个例子 Jtree and frame
这是我的代码
JTree tree = new JTree();
Employee emp = new Employee();
rectutment rec = new rectutment();
interview inter = new interview();
DefaultMutableTreeNode firstLeaf = ((DefaultMutableTreeNode)tree.getModel().getRoot()).getFirstLeaf();
DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
root.add(firstLeaf);
firstLeaf.add(new DefaultMutableTreeNode("firstleaf"));
model.reload();
emp.add(tree);
emp.pack();
emp.setVisible(true);
DefaultMutableTreeNode SecondLeaf = ((DefaultMutableTreeNode)tree.getModel().getRoot()).getLastLeaf();
DefaultTreeModel modelx = (DefaultTreeModel) tree.getModel();
DefaultMutableTreeNode rootx = (DefaultMutableTreeNode) model.getRoot();
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
rootx.add(SecondLeaf);
firstLeaf.add(new DefaultMutableTreeNode("secondleaf"));
modelx.reload();
rec.add(tree);
rec.pack();
rec.setVisible(true);
if (firstLeaf.isNodeDescendant(root)){
emp.setVisible(true);
}
else
if (firstLeaf.isNodeDescendant(root)){
{
rec.setVisible(false);
}
if (SecondLeaf.isLeaf()){
emp.setVisible(true);
}
else
{
rec.setVisible(false);
}
}
}
任何想法?