java - javafx how to expand entire treeItem on button click event? -


in javafx, how expand entire treeitem on button click event ?

i trying replicate accordion effect using treeitem due issues in scrolling while using accordion. please @ code snippet below-

final treeitem<flowpane> rootitem = new treeitem<>(); root.setexpanded(true); (int = 0; < 12; i++) {     treeitem<flowpane> rootitem1 = new treeitem<>(miniflowpane());     treeitem<flowpane> item1 = new treeitem<>(flowpanelarge());     rootitem1.getchildren().add(item1);     rootitem.setexpanded(false); } final treeview<flowpane> tree; tree = new treeview<>(rootitem); tree.setshowroot(false); tree.setminwidth(450.0); tree.setmaxwidth(450.0); hbox listheaderbox = new hbox(); listheaderbox.setalignment(pos.center_left); button b = new button(">"); b.setonaction(new eventhandler<actionevent>() {         @override  public void handle(actionevent event) {   }  });  listheaderbox.getchildren().add(b);  vbox listvbox = new vbox(5.0);  listvbox.getchildren().addall(listheaderbox,tree);  scene scene = new scene(listvbox,500,650);  primartstage.setscene(scene);  primarystage.show(); } 

miniflowpane() , flowpane() functions creates dummy contents , returns flowpane. in button b's click event, how expand children , grandchildren of rootitem ?

how this:

private void expandtreeview(treeitem<?> item){     if(item != null && !item.isleaf()){         item.setexpanded(true);         for(treeitem<?> child:item.getchildren()){             expandtreeview(child);         }     } } 

and add call in button handler:

    button bexpand = new button(">");     bexpand.setonaction(new eventhandler<actionevent>() {          @override         public void handle(actionevent event) {             expandtreeview(rootitem);         }     }); 

and if want add collapse button too:

    button bcollapse = new button("<");     bcollapse.setonaction(new eventhandler<actionevent>() {          @override         public void handle(actionevent event) {             collapsetreeview(rootitem);         }     }); 

where:

private void collapsetreeview(treeitem<?> item){     if(item != null && !item.isleaf()){         item.setexpanded(false);         for(treeitem<?> child:item.getchildren()){             collapsetreeview(child);         }     } } 

edit

if root not visible, calls can made first children:

    bexpand.setonaction(new eventhandler<actionevent>() {          @override         public void handle(actionevent event) {             for(treeitem<?> child: rootitem.getchildren()){                 expandtreeview(child);             }         }     });     bcollapse.setonaction(new eventhandler<actionevent>() {          @override         public void handle(actionevent event) {             for(treeitem<?> child: rootitem.getchildren()){                 collapsetreeview(child);             }         }     }); 

Comments

Popular posts from this blog

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -