JavaFX [1.3] – TreeView


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

For standalone mode

Try all preview controls and give your valuable feedback and file RFEs/Bugs in JavaFX – JIRA

Advertisements

About Rakesh Menon
-

14 Responses to JavaFX [1.3] – TreeView

  1. Pingback: Tweets that mention JavaFX [1.3] – TreeView « Java, JavaFX and beyond… -- Topsy.com

  2. Carl Dea says:

    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

    • Rakesh Menon says:

      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.

  3. Pingback: JavaFX links of the week, May 17 // JavaFX News, Demos and Insight // FX Experience

  4. Selina says:

    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

  5. Amit Vijaykumar says:

    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.

    • Rakesh Menon says:

      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?

      • Amit Vijaykumar says:

        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.

      • Rakesh Menon says:

        TreeView.select(TreeItemBase) must work. I haven’t tried this yet.. If its not working, its an SDK bug.

  6. Amit Vijaykumar says:

    hi
    it is working fine.
    thank you 4 ur support

  7. fuqy says:

    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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: