1

I know I can add a ChangeListener to detect when the tab changed, but I would like to do it before it changed. Here's my situation:

when my user tries to switch tab I do a validation some content on the current tab and the tab should switch only if the validation passes. If I use addChangeListener and switch it back upon validation failure (hoping that it happens fast enough that I won't see it) I will see the tab switched and then immediately switched back which looks stupid.

Something within JTabbedPane is responding to tab click for sure that triggers a state change, I just wonder if this functionality is exposed outside of the class. Either way, is there a good solution for this?

Thanks in advance

user1861088
  • 1,683
  • 2
  • 15
  • 17

1 Answers1

2

Here is a nice approach to do validation before switching tabs by creating a custom VetoableSingleSelectionModel:

Forbid tab change in a JTabbedPane

Community
  • 1
  • 1
Freek de Bruijn
  • 3,552
  • 2
  • 22
  • 28