0
這裏是我的JTree
獲得選擇的節點JTree的java的
javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode(".Net Framework");
javax.swing.tree.DefaultMutableTreeNode treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Install");
javax.swing.tree.DefaultMutableTreeNode treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("V1");
treeNode2.add(treeNode3);
treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("V2");
treeNode2.add(treeNode3);
treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("V3");
treeNode2.add(treeNode3);
treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("V4");
treeNode2.add(treeNode3);
treeNode1.add(treeNode2);
treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Repair");
treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("V1");
treeNode2.add(treeNode3);
treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("V2");
treeNode2.add(treeNode3);
treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("V3");
treeNode2.add(treeNode3);
treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("V4");
treeNode2.add(treeNode3);
treeNode1.add(treeNode2);
treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Removal");
treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Remove All");
treeNode2.add(treeNode3);
treeNode1.add(treeNode2);
jTree2.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
jScrollPane5.setViewportView(jTree2);
這裏是幾乎工程
DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree2.getLastSelectedPathComponent();
if (node == null) {
//Nothing is selected.
return;
}
if (node.isLeaf()) {
System.out.println(node);
}
我希望能夠讓代碼,如果語句說,如果在葉節點V1安裝節點,然後執行此操作。只是不知道if(node.equals(thisleaf)))
怎麼辦,什麼thisleaf
對象應該等於。