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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -