This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTabbedPane - Previously selected Tab.

 
Rob Elliott
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
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,
Rob.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"RE" -

Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it here.

Here's a small example that should help you... you'll have to save the current index and compare it in the ChangeListener...



Thanks! and welcome to the JavaRanch!
 
Paulo Guzman
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can extends JTabbedPane to override the setSelectedIndex method and then call super.setSelectedIndex(index); after doing your validation something like:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic