I’m using a JTabbedPane and want to do some field validation at the moment the user selects another Tab. Potentially, depending on their reply to a messagebox, keep them on the same tab to correct bad data.
I’m implementing the ChangeListener interface and handling stateChanged events however getSelectedIndex() returns the newly selected tab.
Is there easy way to
1) Determine which was the previously selected Tab and
2) Prevent the user from going to the newly selected Tab in the case of data validation failure? A stateChanged event cannot be consumed.
Thanks in advance,
I’m using a JTabbedPane and want to do some field validation at the moment
Share
Hmm you could try something like this which is basically adding a ChangeListener to monitor current tab and to keep previous tab selection:
EDIT: here is a newer version which will only allow a tab change if the validation variable is set to ‘true’ this is done via a button click just to show the logic: