graphics - JavaFX TreeView: setGraphic() for different levels of treeItem -
graphics - JavaFX TreeView: setGraphic() for different levels of treeItem -
i'm creating treeview should have different graphics different levels of treestructure. 3-level structure, root hidden.
the graphic expandable nodes: http://i.imgur.com/wv00cei.png
the graphic leaf nodes:
just label in hbox.
this have tried far, nullpointerexception saying gettreeview null:
customtreecellfactory
public final class customtreecellfactory extends treecell<string>{ private textfield textfield; private hbox hbox; public customtreecellfactory(){ super(); if (gettreeview()==null){ system.out.println("her er problem"); } if (gettreeview().gettreeitemlevel(gettreeitem())==1){ seek { hbox = (hbox) fxmlloader.load(getclass().getresource("/views/trecell.fxml")); } grab (ioexception e) { system.out.println("this didn't work"); e.printstacktrace(); } } else if (gettreeview().gettreeitemlevel(gettreeitem())==2){ seek { hbox = (hbox) fxmlloader.load(getclass().getresource("/views/trecelllowestlevel.fxml")); } grab (ioexception e) { system.out.println("this didn't work"); e.printstacktrace(); } } }
code snippet set cell factory
treeview<string> tree = (treeview) parent.getchildren().get(0); tree.setroot(root); tree.setshowroot(false); tree.seteditable(true); tree.setcellfactory(new callback<treeview<string>, treecell<string>>() { @override public treecell<string> call(treeview<string> param) { homecoming new customtreecellfactory(); } });
i found out problem was.
what tried needed done in update-method, when treeview set.
here's code solved problem:
**constructor** public customtreecellfactory(){ seek { hbox = (hbox) fxmlloader.load(getclass().getresource("/views/trecell.fxml")); } grab (ioexception e) { system.out.println("this didn't work"); e.printstacktrace(); } seek { hboxleaf = (hbox) fxmlloader.load(getclass().getresource("/views/trecelllowestlevel.fxml")); } grab (ioexception e) { system.out.println("this didn't work"); e.printstacktrace(); } }
update method
@override public void updateitem(string item, boolean empty) { super.updateitem(item, empty); if (item != null) { if (gettreeview().gettreeitemlevel(gettreeitem())==1) { setgraphic(this.hbox); }else if (gettreeview().gettreeitemlevel(gettreeitem())==2){ setgraphic(this.hboxleaf); } } else { setgraphic(null); } }
graphics javafx treeview
Comments
Post a Comment