Two Laptop Bag*
The moose likes Swing / AWT / SWT and the fly likes JTabbedPane - Previously selected Tab. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTabbedPane - Previously selected Tab." Watch "JTabbedPane - Previously selected Tab." New topic
Author

JTabbedPane - Previously selected Tab.

Rob Elliott
Greenhorn

Joined: Apr 24, 2002
Posts: 9
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

Joined: Oct 18, 2000
Posts: 4121

"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!


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Paulo Guzman
Greenhorn

Joined: Dec 07, 2010
Posts: 2
You can extends JTabbedPane to override the setSelectedIndex method and then call super.setSelectedIndex(index); after doing your validation something like:

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTabbedPane - Previously selected Tab.