Javafx Tree Table view: how to assign serial number to the direct child nodes of the root node -


i trying number direct child nodes of root node in serial manner (child-1, child-2...).
here method sets cell value factory mycolumn:

private void setcellvaluefactory() {     mycolumn.setprefwidth(120);     final int[] si_subsetcount = {         1     };     mycolumn.setcellvaluefactory(     (treetablecolumn.celldatafeatures < mydataclass, string > p) - > {         treeitem < jvcc_pageheaderinfo > ti_row = p.getvalue();         mydataclass mydataclass = p.getvalue().getvalue();         string text;         if (ti_row.isleaf()) {             //leaf         } else if (ti_row.getparent() != null) {             text = "child-" + si_subsetcount[0];             si_subsetcount[0]++;         } else {             si_subsetcount[0] = 1;             text = "root";         }         return new readonlyobjectwrapper < > (text);     });  } 

but output below:

>root   >child-4     >leaf     >leaf   >child-8     >leaf     >leaf 

i don't understand why numbering 4, 8... instead of 1, 2...

can me this.

that because can not control, when cellvaluefactorys method evaluating value each row called. might called several times single row, why counter not show correct value each line.

a dynamical approach prefered here. if should have differ between 3 node levels root/child/leaf, this:

mycolumn.setcellvaluefactory( ( final celldatafeatures<string, string> p ) -> {   final treeitem<string> value = p.getvalue();   string text = "";    if ( value.isleaf() )     text = "leaf";   else if ( value.getparent() != null )     text = "child-" + (value.getparent().getchildren().indexof( value ) + 1);   else     text = "root";    return new readonlystringwrapper( text ); } ); 

since children of treeitem stored in observablelist, can ask them index , add 1, since index starts @ zero.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -