1
votes

Using JavaFX 2.2 I have a window which consists mainly of a TabPane with 4 Tabs. The user may make changes to data presented in any of the tabs, and if they do, I want to make sure they don't loeave that tab until they've saved/cancelled/updated the data. In particular I want to make sure they don't select a different tab. I can catch if they're trying to quit or execute some menu item, but I can't seem to find a way to interrupt a tab change. I can catch when they've clicked on a new tab (onSelectionChanged), and ask if they really want to discard their edits, but then the tab change happens anyway. Help greatly appreciated.

2

2 Answers

1
votes

You can disable other tabs until user clicks 'Save' or 'Cancel'

1
votes

Get the selection model of the tab pane, monitor it's selected index property for changes and, when you detect a change ask your tab if it is ok to change now - if not, set the selected index back to the currently selected tab, overriding the selection change to a new tab.