Forums Register Login

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

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
Yeah, but does being a ninja come with a dental plan? And what about this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 545 times.
Similar Threads
Reg Tab Key in JTabbedPane
Reg Tab Key in JTabbedPane
Proper Event Processing
Trouble with model for calculating and adding table values dependent on multiple rows
Converting an application to Java (new to Java)
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 16:39:59.