Codigo
import java.awt.BorderLayout; import java.awt.Dimension; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTabbedPane; import javax.swing.JTextArea; public class Main extends JFrame { public Main() { try { jbInit(); } catch (Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception { this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); this.getContentPane().setLayout( new BorderLayout() ); this.setSize( new Dimension(400, 300) ); this.setTitle( "Test" ); /* crear y agregar al formulario aqui vamos a crear el JTabbedPane y tres JPanel que usaremos como pestañas */ JTabbedPane tabPanel = new JTabbedPane(); /* creamos un panel para cada pestaña */ JPanel tabA = new JPanel(); tabA.setPreferredSize( new Dimension(100,100) ); tabA.setLayout( new BorderLayout() ); JPanel tabB = new JPanel(); tabB.setPreferredSize( new Dimension(100,100) ); tabB.setLayout( new BorderLayout() ); JPanel tabC = new JPanel(); tabC.setPreferredSize( new Dimension(100,100) ); tabC.setLayout( new BorderLayout() ); /* ahora crear un boton, para la pestaña A */ JButton botonTabA = new JButton("Boton"); tabA.add( botonTabA , BorderLayout.CENTER ); /* un label para la pestaña B */ JLabel labelTabB = new JLabel(); labelTabB.setText("Label"); tabB.add( labelTabB , BorderLayout.CENTER ); /* un textarea para la pestaña C */ JTextArea textTabC = new JTextArea(); textTabC.setText("texto"); tabC.add( textTabC , BorderLayout.CENTER ); /* aqui se crean las pestañas a partir de los panels */ tabPanel.addTab( "Tab A" , tabA ); tabPanel.addTab( "Tab B" , tabB ); tabPanel.addTab( "Tab C" , tabC ); /* agregar al formulario el componente JTabbedPane */ this.getContentPane().add( tabPanel , BorderLayout.CENTER ); } public static void main(String[] args) { Main m = new Main(); m.setVisible(true); } }
Descargar Proyecto en JDeveloper 11g
ademas las pestañas pueden habilitarse/deshabilitarse con el método
setEnabledAt de la clase jTabbedPane
http://download.oracle.com/javase/6/docs/api/javax/swing/JTabbedPane.html#setEnabledAt(int, boolean)