This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Q: JTabbedPane / Method call when leaving a tab and when entering another one  RSS feed

 
Charles Van Damme
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a nice day.
Here is a question which, I think, is of concern to a large Swing-JTabbedPane users and which does not appear in the Sun-Oracle tutorial http://docs.oracle.com/javase/tutorial/uiswing/components/tabbedpane.html

How to add functionality to the hidden 'Action Listener' of JTabbedPane to obtain the two following functionalities, when passing from Tab_Panel_1 to Tab_Panel_2 ?

- To call a home made function as very last task when the 'tab selection change' is triggered and just before control and visibility are leaving Tab_Panel_1.
For example : Calculations and table fillings need to be operated. One assume that the fact of leaving Tab_Panel_1 (by clicking another 'tabPanel') means that the input data in Tab_Panel_1 are completely introduced and that calculations and/or table fillings may occur (to be used by other 'Tab_Panel's).

- At the moment of entering Tab_Panel_21 or Tab_Panel_22, the very first task is to use the previous calculation results and/or table fillings as input parameter of methods own to Tab_Panel_21 and Tab_Panel_22.
For example, these data are further processed and used to feed a graph, different for Tab_Panel_21 and Tab_Panel_22.

?
?
?

An idea of statements to be used? An example of code ?
Thanks by advance.
 
Stephan van Hulst
Saloon Keeper
Posts: 7817
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the best way to do this is to add a ChangeListener to your JTabbedPane. The ChangeEvent itself won't tell you much, but it will fire after the selection has changed, and before the UI is repainted.

You need to keep track of the currently selected tab, and when the ChangeEvent fires, do what you want with that tab, update the tracking variable and then do what you want with the new tab.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!