JTabbedPane

The JTabbedPane control is available in Swing. This component appears as a group of folders in a file cabinet. Each folder has a title. When a user selects a folder, its contents become visible. Only one of the folders can be selected at a time.

void addTab ( String str, Component comp)

Here, str is the title for the tab. Comp is the component that should be added to the tab.

Program

yutuy

 

 

 

Program Source

import javax.swing.JFrame;
import javax.swing.JTabbedPane;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.FlowLayout;

class Frame extends JFrame {
 
    Frame()
    {
        setTitle("JTabbedPane");
        setLayout(new FlowLayout());
        setJTabbedPane();
        setSize(700,250);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
 
    private void setJTabbedPane()
    {
        JTabbedPane tp = new JTabbedPane();
        tp.addTab("ButtonPanel", addButtonPanel());
        tp.addTab("TextFieldPanel", addTextFieldPanel());
        add(tp);
    }
 
    private JPanel addButtonPanel()
    {
        JPanel jb = new JPanel();
        jb.add(new JButton("JButton1"));
        jb.add(new JButton("JButton2"));
        jb.add(new JButton("JButton3"));
        return jb;
    }
 
    private JPanel addTextFieldPanel()
    {
        JPanel jb = new JPanel();
        jb.add(new JLabel("JTextField1"));
        jb.add(new JTextField(10));
        jb.add(new JLabel("JTextField2"));
        jb.add(new JTextField(10));
        jb.add(new JLabel("JTextField3"));
        jb.add(new JTextField(10));
        return jb;
    }
}

public class Javaapp {
 
    public static void main(String[] args) {
     
       Frame fr = new Frame();
    }
}

Leave a Comment