JavaFX TreeView, I was right

Way back in April I complained that the JavaFX TreeView was designed in a strange and overly convoluted way because it made use of a VirtualFlow. It seemed bizarre to me (and still does) that you would be forced to constantly recreate cells rather than create them once and lay them out as needed. My argument was (and still is) that if you need to show thousands of items of data to a user in a tree then you are doing it wrong and so TreeView was not engineered with usage in mind, it was designed to make use of a technology that was completely inappropriate for the use case, not least because you can’t remove the damn VirtualFlow from it. So I created my own “TreeView” and have used that within QW.

The tree has worked really well but up until now I didn’t have an example of it being pushed to its limits.

Over the past week I have been implementing the Problem Finder Sidebar, be honest how many of you even knew it existed? Today, after fixing an unrelated bug I found a (somewhat) real-life example. Enter the QW Problem Finder, a contrived rule and The Adventures of Sherlock Holmes. The stories of Sherlock Holmes is my “go to” project for testing changes and features in QW. It has a lot of chapters and a lot of text and is in the public domain so screenshots are not a problem. The sidebar will display all problems found for a specified rule for all chapters. In this case I had reduced the constraints to a point where hundreds of problems were found, the sidebar then displays them in a handy tree.

Notice the numbers in brackets? That is the number of problems found per chapter. Even at this number of items the tree works very well with no slow down, things are snappy and responsive and not a VirtualFlow in sight.

I know I’m biased but I find my implementation of a tree is so much easier to use (and far more intuitive) than the JavaFX TreeView. Consider:

// Create the Tree.
QuollTreeView<Object> tree = new QuollTreeView<> ();
tree.setShowRoot (false);

// Set the cell provider, i.e. the thing that creates the nodes that are displayed.
tree.setCellProvider (treeItem ->
    Label l = new Label (treeItem.getValue ().toString ());
    return l;

// Create and set the model.
TreeItem<Object> root = new TreeItem<> ();
root.setValue ("Hello World");
tree.setRoot (root);

No muss, no fuss and I can use it anywhere, I don’t have to worry about scrollbars appearing and disappearing when the view decides it needs them.

Sometimes it’s nice to be vindicated, but if you are showing this many items to a user you are doing it wrong.

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

%d bloggers like this: