Joel
Joel

Reputation: 2688

JavaFX Tree - Veto selection change

I would like to be able to "veto" a selection change on a tree. I'd like to pop-up a dialog warning the user to save before the change. How do I do this with JavaFX TreeView?

I've tried to figure out how to swap out the SelectionModel but w/o luck, because I want to use a SingleSelectionModel, but there's no setter (on TreeView) to do so.

Upvotes: 1

Views: 439

Answers (1)

Joel
Joel

Reputation: 2688

There's a good example of how to pull this off in the Scene Builder source code. Essentially listen to a tree change. If you don't like the "proposed change", or need to pop-up a dialog box, do so. If the change isn't appropriate, then stop listening for changes, make the change, and re-listen.

Upvotes: 1

Related Questions