|
Re: JTabbedPane..
|
Posted: Apr 1, 2002 2:17 PM
|
|
It was really very tough question. It took me more than three days to figure it out!!!!!! I think you can add a ChangeListener to JTabbedPane and you are notified when you select a tab page.
Thanks Kishori ///////////////////
import java.awt.* ;
import javax.swing.* ;
public class FrameTest extends JFrame {
JButton b1 = new JButton ( "Hello 1" ) ;
JButton b2 = new JButton ( "Hello 2" ) ;
JTabbedPane tab = new JTabbedPane() ;
JPanel p1 = new JPanel ( ) ;
JPanel p2 = new JPanel ( ) ;
public FrameTest () {
setBounds ( 20, 20 , 300, 300 ) ;
p1.add ( b1 ) ;
p2.add ( b2 ) ;
tab.addTab ( "Tab 1", p1 );
tab.addTab ( "Tab 2", p2 );
getContentPane().add ( tab , "Center" ) ;
// Add change lister to your tab so that you get notified
// when you click on any tab page
tab.addChangeListener ( new javax.swing.event.ChangeListener ( ) {
public void stateChanged( javax.swing.event.ChangeEvent e) {
System.out.println ( "selected Index:" + tab.getSelectedIndex ( ) ) ;
}
}
) ;
}
public static void main ( String[] args ) {
FrameTest f = new FrameTest () ;
f.show ( ) ;
}
}
|
|