Singh M.
Posts: 154
Nickname: ms
Registered: Mar, 2002
|
|
Re: Action on JTabbedPane
|
Posted: Jun 13, 2003 7:20 PM
|
|
> Hello world, > > I would like to know How can I get the following event : > "User change of active Tab in a JTabbedPane" > > It'll help me so... thanks a lot..
You will have to register changeListener with your JTabbedPane.
eg.
if you have a JTabbedPane _tabbedPane, after instantiating, you add a changeListener to _tabbedPane...
_tabbedPane.addChangeListner(new YourChangeListener());
-------
now, this class called YourChangeListener, will get notifications if a diffrent tab is selected.
the definition of the class will look like this:
public class YourChangeListener implements ChangeListener{
//you will also need a method called stateChanged
public void stateChanged(ChangeEvent changeEvent) {
JTabbedPane sourceTabbedPane = (JTabbedPane)changeEvent.getSource();
int index = sourceTabbedPane.getSelectedIndex();
System.err.println("Currently selected tab no. is : "+index);
}
}
|
|