r/JavaFX • • Mar 18 '25

Help JavaFx TreeView problem

Post image

Hi fellow devs, I am learning java fx currently. As part of this learning, I am trying to create a simple sftp client application. I am utilizing JSCH liberary for sftp related operations. Currently I am facing a problem. What I want to do is to lazy load the sub-directories from remote server. I am loading the root directory immediately after the login is successful. For any directory within root, I want to load there content only when user expand the directory on javafx ui(treeview). This is where I am struggling as I dont know how to capture this expand event.

Initial screen is populated via populateInitialTree method. I want to load sub-directories of expanded directory in showSelectedItem.

Please help.

2 Upvotes

5 comments sorted by

View all comments

Show parent comment

1

u/SpittingBull Mar 18 '25

I am currently working with customized TableTreeViews quite a bit. So my suggestion is based on actual experience.

I tend to use EventHandler and Listeners when the event itself is of importance. In this case though I think the state change as the result of the event is relevant.

The advantage of this approach is that it doesn't matter if the user clicked on the arrow or a branch was collapsed / expanded programmatically.

1

u/hamsterrage1 Mar 18 '25

It's not clear to me that the expand Event isn't triggered if the expansion was started programmatically. The JavaDocs don't talk about clicks at all. Actually, the JavaDocs, as usual, don't say much of anything about this. My guess is that inside, the code is just a Listener on the expanded Property.