I'm having my first time with java Swing and I wondering if can I add values for each DefaultMutableTreeNode and refer to them by selecting specific node?
e.g. Calling specific powershell script by selecting node from Jtree model (1 node = 1 script). I'm really newbie and I will be greatful if somebody could explain or redirected me to some solution ;p
private JTree setTab2Tree() {
JTree tree;
DefaultMutableTreeNode root = new DefaultMutableTreeNode("Customers");
DefaultMutableTreeNode webClient = new DefaultMutableTreeNode("Web");
webClient.add(new DefaultMutableTreeNode("Person Customer"));
webClient.add(new DefaultMutableTreeNode("Firm Customer"));
DefaultMutableTreeNode appClient = new DefaultMutableTreeNode("App");
appClient.add(new DefaultMutableTreeNode("Person Customer"));
appClient.add(new DefaultMutableTreeNode("Firm Customer"));
root.insert(webClient, 0);
root.insert(appClient, 1);
tree = new JTree(root);
for (int i = 0; i < tree.getRowCount(); i++) {
tree.expandRow(i);
}
tree.setRootVisible(false);
tree.setShowsRootHandles(true);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.addTreeSelectionListener(new MainTree.SelectionListener());
tree.setBorder(BorderFactory.createLineBorder(Color.black));
add(new JScrollPane(tree));
}