Get checked items of a TreeView in JavaFX

 27. Januar 2019 •  Ekkart •  javafx, treeview •  ToDo

JavaFX provides an easy way to implement Java GUIs. Unfortunately, some methods or concepts are missing.

I used a TreeView component with CheckBoxTreeItems. When evaluating the input I want to get all checked items from the TreeView, resp. its SelectionModel.

The standard method getSelectedItems just returns the selected items, when selecting means the last clicked (i.e. selected) element.

Thus I had to write my own code for traversing the tree and collecting all checked elements. This is not difficult, but a bit tiresome, as there are many methods missing that have to be implemented.

If you’re interested in the code, see

https://gitlab.com/ekleinod/edgeutils/blob/master/edgeutils/src/main/java/de/edgesoft/edgeutils/javafx/TreeViewUtils.java

for my implementation. As I state in the documentation, using Kotlin should provide means to extend the TreeView class itself, but this is future talk.