Im making a simple treeview on NetBeans and id like to know how can i add a description to a determined selected node, through a button that have a function that will associate to a lable.
Click to see Treeview Image here
the link shows the image of what i want to do, by clicking ">>" it will add a description to that lable and associate to that selected node.
this is the code for the ">>" button.
private void add2ActionPerformed(java.awt.event.ActionEvent evt) {
lTree2.setText(tf2.getText());
}
obviously this isnt what i want, i just put here show what i want.
You want to create your own class for tree nodes, as a subclass of whatever you're using now, adding a
description
field and corresponding accessors in the subclass. For example, if you're usingDefaultMutableTreeNode
:Once you've done that, in your
actionPerformed()
for the button you want to get the selected tree node, get the description out of it, and set the text in the label: