1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
| import java.awt.*;
import javax.swing.*;
class TabbedPaneExample
extends JFrame
{
private JTabbedPane tabbedPane;
private JPanel [] panel=new JPanel[3];
//private JPanel panel2;
//private JPanel panel3;
public TabbedPaneExample()
{
// NOTE: to reduce the amount of code in this example, it uses
// panels with a NULL layout. This is NOT suitable for
// production code since it may not display correctly for
// a look-and-feel.
setTitle( "Tabbed Pane Application" );
setSize( 300, 200 );
setBackground( Color.gray );
JPanel topPanel = new JPanel();
topPanel.setLayout( new BorderLayout() );
getContentPane().add( topPanel );
// Create the tab pages
createPage1();
// Create a tabbed pane
JTabbedPane tabbedPane = new JTabbedPane();
//panel[0] = new JPanel();
//panel[1] = new JPanel();
//panel[2] = new JPanel();
tabbedPane.addTab( "Page 1", panel[0] );
tabbedPane.addTab( "Page 2", panel[1] );
tabbedPane.addTab( "Page 3", panel[2] );
//topPanel.setBorder(BorderFactory.createTitledBorder("xxx"));
topPanel.add( tabbedPane, BorderLayout.CENTER );
}
public void createPage1()
{
for(int i=0;i<3;i++)
{
panel[i] = new JPanel();
panel[i].setLayout( null );
JLabel label1 = new JLabel( "Username:"+i+"" );
label1.setBounds( 10, 15, 150, 20 );
panel[i].add( label1 );
JTextField field = new JTextField();
field.setBounds( 10, 35, 150, 20 );
panel[i].add( field );
JLabel label3 = new JLabel( "Password:"+i+"" );
label3.setBounds( 10, 60, 150, 20 );
panel[i].add( label3 );
JPasswordField fieldPass = new JPasswordField();
fieldPass.setBounds( 10, 80, 150, 20 );
panel[i].add( fieldPass );
panel[i].setBorder(BorderFactory.createTitledBorder("n"+i+""));
}
//panel[2].setBorder(BorderFactory.createTitledBorder("nnn"));
}
// Main method to get things started
public static void main( String args[] )
{
// Create an instance of the test application
TabbedPaneExample mainFrame = new TabbedPaneExample();
mainFrame.setVisible( true );
}
} |