java - TreeView - Jtree (NetBeans) How to add a description to a node -


im making simple treeview on netbeans , id know how can add description determined selected node, through button have function associate lable.

click see treeview image here

the link shows image of want do, clicking ">>" add description lable , associate selected node.

this code ">>" button.

private void add2actionperformed(java.awt.event.actionevent evt) {                                         ltree2.settext(tf2.gettext()); } 

obviously isnt want, put here show want.

you want create own class tree nodes, subclass of whatever you're using now, adding description field , corresponding accessors in subclass. example, if you're using defaultmutabletreenode:

class mynode extends defaultmutabletreenode {     private string description;     ...     public void setdescription(string descr) {         description = descr;     }      public string getdescription() {         return description;     } } 

once you've done that, in actionperformed() button want selected tree node, description out of it, , set text in label:

private void add2actionperformed(java.awt.event.actionevent evt) {                                          mynode node = (mynode)tree.getlastselectedpathcomponent();     string descr = node.getdescription();     ltree2.setztext(descr);  }         

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -