eclipse 已经安装好了swt-designer插件

2024-12-05 17:23:39
推荐回答(1个)
回答1:

AWT的?
SWING的我知道.
DefaulMutableTreeNode root = DefaultableTreeNode("根节点");
......
JTree jTree1 = new JTree(root);
jTree1.addTreeSelectionListener(new Frame1_jTree1_treeSelectionAdapter(this));

class Frame1_jTree1_treeSelectionAdapter implements TreeSelectionListener{
private TreeFrame adaptee;
Frame1_jTree1_treeSelectionAdapter(TreeFrame adaptee){
this.adaptee = adaptee;
}
public void valueChanged(TreeSelectionEvent e){
adaptee.jTree1_valueChanged(e);
}
}
public void jTree1_valueChanged(TreeSelectionEvent e){
DefaulMutableTreeNode node = (DefaulMutableTreeNode)jTree1.getLastSelectedpathcomponent();//得到你选择的节点
String name = node.getUserObject().toString();//得到节点的名这样就可以根据选择不同的名来做不同的事
......
}