Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Swing Tabbed Pane Changing Event

Status
Not open for further replies.

jsulman

Programmer
Jun 14, 2001
85
US
Greetings,
Does anybody know how to capute a changing event on a Tabbed Pane? This would be the event before the tab actually changes.

Thank You in Advance

Jeff Sulman
 
Try this:

Code:
jTabbedPane.addChangeListener(new ChangeListener()
   {
      public void stateChanged(ChangeEvent e)
      {
         // do something
      }
   });
 
idarke,
Thanks for the repsonse. From what I understand the ChangeListener trapps the event when it has changed. So if I am going from Tab A to Tab B the code will only have access to Tab B and will not know that the previous tab was Tab A. I have a popup menu on a Tab and when I switch from Tab A to Tab B the menu still appears, if it had not been closed before changing tabs. If I can trap the event that occurs before the tab actually changes (traditinoally know as the OnTabChanging even or something like that) I will have acess to the tab and be able to remove the popup.

Thanks again.

Jeff
 
I understand your problem. Even an InternalFrameListener doesn't get any events when the tab is changed. Basically the UI considers the tabbed pane as one big container, always displayed and active.

What I ended up doing was making all my JInternalFrame objects globally accessable (I made them static) so when the stateChanged event occured, I could examine them and do any needed cleanup on them. In your case, remove all popups.
 
idarke,
Thanks for the help. I found another work around to the problem. I create a class variable int previousSelectedTabIndex that stores the previous selected tab. When i go it ChangListener I can get the provious tab, do what i want to it and then set the previousSelectedTabIndex equal to the current index so its ready for the next tab change.

Not as elegant as yours but it works.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top