I have some validation that I perform when the user clicks on a tab. If validation == true then allow the tab to show (or to switch to). Right now I am using the StateChanged event to validate. The problem is, when you click on a tab it shows the tabs contents and if validation == false it switches back to previous tab. I do not want it to switch to at all unless validation == true. How do I do this, am I checking for a wrong event? Thank you all
You can use the method tab.setEnabledAt(index, false) to disable the tab if validation = false, and tab.setEnabledAt(index, true) to turn it back on when validation = true.
Edit: Disabling a tab will grey it out so the user can't click it in the first place, which means you're going to have to perform the validation check before the user click the tab.
Try override JTabbedPane.setSelectedIndex(int index).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With