Stop changing tabs in a JTabbedPane

Hi,

I'm using a JTabbedPane and at some point, I need to prevent it from leaving a particular tab (due to a condition), even though the user wants to go to a different  tab . Is this possible with JTabbedPane. I also want to make sure that stateChanged listener doesn't get called.

Thanks
anthony0007Asked:
Who is Participating?
 
hoomanvCommented:
you can disable the other tabs so he cant move to them
using JTabbedPane.setEnabledAt(int index, boolean enabled)
0
 
CEHJCommented:
Personally i wouldn't do that. Your users will probably just think your ui is broken
0
 
anthony0007Author Commented:
Isn't there any other way to prevent it from moving to other tabs. stateChanged Listener gets called once the tab has been changed.
If I can capture an event before tab changes, then it might be helpful.
0
 
JavatmCommented:
Well I can only see to option :

1. Either disable the item or
2. Blast a JOptionPane if he goes to other tabs while there is unfinish
task this will not allow him to go to the next tab if you trap it with
a dialog to remind him.
0
 
objectsCommented:
yyou would disable the other tabs as hoomanv suggested.
then reenable them when they are allowed to change again.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.