Source of JTabbedPaneFrame.java


  1: // Fig. 22.21: JTabbedPaneFrame.java
  2: // Demonstrating JTabbedPane.
  3: import java.awt.BorderLayout;
  4: import java.awt.Color;
  5: import javax.swing.JFrame;
  6: import javax.swing.JTabbedPane;
  7: import javax.swing.JLabel;
  8: import javax.swing.JPanel;
  9: import javax.swing.JButton;
 10: import javax.swing.SwingConstants;
 11: 
 12: public class JTabbedPaneFrame extends JFrame  
 13: {
 14:    // set up GUI
 15:    public JTabbedPaneFrame()
 16:    {
 17:       super( "JTabbedPane Demo " );
 18: 
 19:       JTabbedPane tabbedPane = new JTabbedPane(); // create JTabbedPane 
 20: 
 21:       // set up pane11 and add it to JTabbedPane 
 22:       JLabel label1 = new JLabel( "panel one", SwingConstants.CENTER );
 23:       JPanel panel1 = new JPanel(); // create first panel
 24:       panel1.add( label1 ); // add label to panel
 25:       tabbedPane.addTab( "Tab One", null, panel1, "First Panel" ); 
 26:       
 27:       // set up panel2 and add it to JTabbedPane
 28:       JLabel label2 = new JLabel( "panel two", SwingConstants.CENTER );
 29:       JPanel panel2 = new JPanel(); // create second panel
 30:       panel2.setBackground( Color.YELLOW ); // set background to yellow
 31:       panel2.add( label2 ); // add label to panel
 32:       tabbedPane.addTab( "Tab Two", null, panel2, "Second Panel" ); 
 33: 
 34:       // set up panel3 and add it to JTabbedPane
 35:       JLabel label3 = new JLabel( "panel three" );
 36:       JPanel panel3 = new JPanel(); // create third panel
 37:       panel3.setLayout( new BorderLayout() ); // use borderlayout
 38:       panel3.add( new JButton( "North" ), BorderLayout.NORTH );
 39:       panel3.add( new JButton( "West" ), BorderLayout.WEST );
 40:       panel3.add( new JButton( "East" ), BorderLayout.EAST );
 41:       panel3.add( new JButton( "South" ), BorderLayout.SOUTH );
 42:       panel3.add( label3, BorderLayout.CENTER );
 43:       tabbedPane.addTab( "Tab Three", null, panel3, "Third Panel" );
 44: 
 45:       add( tabbedPane ); // add JTabbedPane to frame
 46:    } // end JTabbedPaneFrame constructor
 47: } // end class JTabbedPaneFrame
 48: 
 49: /**************************************************************************
 50:  * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and               *
 51:  * Pearson Education, Inc. All Rights Reserved.                           *
 52:  *                                                                        *
 53:  * DISCLAIMER: The authors and publisher of this book have used their     *
 54:  * best efforts in preparing the book. These efforts include the          *
 55:  * development, research, and testing of the theories and programs        *
 56:  * to determine their effectiveness. The authors and publisher make       *
 57:  * no warranty of any kind, expressed or implied, with regard to these    *
 58:  * programs or to the documentation contained in these books. The authors *
 59:  * and publisher shall not be liable in any event for incidental or       *
 60:  * consequential damages in connection with, or arising out of, the       *
 61:  * furnishing, performance, or use of these programs.                     *
 62:  *************************************************************************/