JavaFX [1.3] – TreeView
May 10, 2010 14 Comments
JavaFX 1.3 has TreeView as preview control. Here I’ll demonstrate how to use it to implement a File Browser. For this, we need to implement a custom TreeView.cellFactory which will return a TreeCell instance (View) and provide an implementation for TreeItem (Model). TreeItem.createChildren is implemented so as to add more and more items, as and when user expands the nodes (Drive/Directory).
For Applet mode, click on above image
Try all preview controls and give your valuable feedback and file RFEs/Bugs in JavaFX – JIRA






Pingback: Tweets that mention JavaFX [1.3] – TreeView « Java, JavaFX and beyond… -- Topsy.com
Rakesh,
Nice demo. I played with it a little testing and notice the 2 things:
1) a single click doesn’t expand a folder.
2) tab key doesn’t advance focus to next tree item.
Interesting I ran this in a jre1.6update20 with JavaFX 1.2.3 and things seem to still work.
I really like the look and feel of this new control. Can’t wait to used it in an app. I don’t know how focus policy would be honored in the JavaFX scene graph.
Thanks!
Carl
Thanks Carl! Yes it needs to expand on single-click (Bug for TreeView). I think tab should take focus to next control. For traversing through items, you can use arrow keys. I’m not sure if it will run on 1.2.3 (those are new classes), you ran it in standalone mode? Yes, Its easy to customize the looks… Yeah! I still use the old way of customizing UI (code), have to move to CSS style..
Yes, we need to improve the focus handling, its not as flexible/defined compared to AWT.
Pingback: JavaFX links of the week, May 17 // JavaFX News, Demos and Insight // FX Experience
Rakesh,
Can I customize background of TreeView? I want to set it a pure color. I try the css property -fx-background-color. But it only change the border not background.
Thanks,
Selina
Yes. I think we also need to change the item-fill properties. I’ll try it out and get you the exact css.
Please refer to new post: http://rakeshmenonp.wordpress.com/2010/05/28/javafx1-3-power-of-css/
hi
i am trying to get focus on a tree’s child programatically. but the child of the root is not getting highlighted. i also tried to set focus (requestfocus()) on the “data” attribute of TreeItemBase but it is not working. i am using Hyperlink in the data.
I’m not clear on requirement here. You must be able to focus tree and select the item using select(TreeItemBase).
Or may be your requirement is to differentiate between an anchor item and selected item?
hi
actually i have created a treeview in my program and now i want to provide a search facility to user. for that i have displayed a textbox and a button. when the user types the text and presses the button i need to programatically traverse the treeview, expand the relevant root and get the matching leaf highlighted.
i am able to traverse the tree and get the text in the tree. but i am not able to highlight the leaf so that the user comes to know this leaf is selected.
TreeView.select(TreeItemBase) must work. I haven’t tried this yet.. If its not working, its an SDK bug.
hi
it is working fine.
thank you 4 ur support
Glad…Thanks…
hi Rakesh
can i operate the tree’s child? for example, when i click the mouse, something will happens in the stage. i mean, how can i use mouseEvents in the treeview? thx