Example usage for javax.swing JTabbedPane add

List of usage examples for javax.swing JTabbedPane add

Introduction

In this page you can find the example usage for javax.swing JTabbedPane add.

Prototype

public void add(Component component, Object constraints) 

Source Link

Document

Adds a component to the tabbed pane.

Usage

From source file:Main.java

public static void main(String[] args) {

    JFrame frame = new JFrame();

    JButton btn = new JButton("Test");

    JPanel panel = new JPanel();
    panel.add(btn);// w  ww . j  ava 2s. c om

    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.add("Tab1", panel);

    frame.add(tabbedPane, BorderLayout.CENTER);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setMinimumSize(new Dimension(300, 300));
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    int MAX_CELLS = 30;

    DefaultListModel<String> listModel = new DefaultListModel<>();
    JList<String> myList = new JList<>(listModel);
    myList.setVisibleRowCount(8);//  w w  w  . j a  v  a2s. co  m

    for (int i = 0; i < MAX_CELLS; i++) {
        listModel.addElement("label " + i);
    }

    JTabbedPane jTabbedPane = new JTabbedPane();

    jTabbedPane.add("Test", new JScrollPane(myList));

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(jTabbedPane);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    final JTabbedPane jtp = new JTabbedPane();
    jtp.add("One", createPanel());
    jtp.add("Two", createPanel());
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(jtp);//from w  ww  . ja  v  a2 s.  c om
    f.pack();
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JPanel panel = new JPanel();
    panel.setLayout(new OverlayLayout(panel));

    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.add("1", new JTextField("one"));
    tabbedPane.add("2", new JTextField("two"));
    tabbedPane.setAlignmentX(1.0f);//from   www . j a  va2 s .  c  om
    tabbedPane.setAlignmentY(0.0f);

    JCheckBox checkBox = new JCheckBox("Add tab");
    checkBox.setOpaque(false);
    checkBox.setAlignmentX(1.0f);
    checkBox.setAlignmentY(0.0f);

    panel.add(checkBox);
    panel.add(tabbedPane);

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(panel);
    frame.setSize(400, 100);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JPanel panel = new JPanel();
    panel.setLayout(new OverlayLayout(panel));

    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.add("1", new JTextField("one"));
    tabbedPane.add("2", new JTextField("two"));
    tabbedPane.setAlignmentX(1.0f);//  ww  w.  j  a  v a 2  s  .  c o  m
    tabbedPane.setAlignmentY(0.0f);

    JCheckBox checkBox = new JCheckBox("Check Me");
    checkBox.setOpaque(false);
    checkBox.setAlignmentX(1.0f);
    checkBox.setAlignmentY(0.0f);

    panel.add(checkBox);
    panel.add(tabbedPane);

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(panel);
    frame.setLocationByPlatform(true);
    frame.setSize(400, 100);
    frame.setVisible(true);
}

From source file:TabComponent.java

public static void main(String[] args) {
    JTabbedPane pane = new JTabbedPane();
    String title = "Tab";
    pane.add(title, new JLabel(title));
    pane.setTabComponentAt(0, new TabComponent(title, pane));

    JFrame frame = new JFrame("Tab Component Demo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(pane);// w w w  . ja va2 s .c o  m
    frame.setSize(500, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    try {/*from  w  w  w. ja  va 2  s . c o m*/
        bg = ImageIO.read(new URL("http://www.java2s.com/style/download.png"));
    } catch (Exception ex) {
        System.out.println(ex);
    }

    JPanel tabPanel = new JPanel(new GridBagLayout()) {
        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            g.drawImage(bg, 0, 0, getWidth(), getHeight(), this);
        }

        @Override
        public Dimension getPreferredSize() {
            return new Dimension(400, 300);
        }
    };
    JPanel buttons = new JPanel(new GridLayout(4, 1, 15, 15));
    buttons.setOpaque(false);
    for (int i = 0; i < 4; i++) {
        buttons.add(new JButton("Button"));
    }
    tabPanel.add(buttons);

    JTabbedPane tabPane = new JTabbedPane();
    tabPane.add("Panel with Bachground", tabPanel);

    JFrame frame = new JFrame();
    frame.setContentPane(tabPane);
    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JTabbedPane tabbedPane = new JTabbedPane();
    for (int i = 0; i < 5; i++) {
        tabbedPane.add("Tab " + i, new JLabel("Label " + i, SwingConstants.CENTER));
    }/*  w w w  .  ja v  a 2  s  .  c  om*/

    tabbedPane.getModel().addChangeListener(e -> {
        JLabel label = (JLabel) tabbedPane.getSelectedComponent();
        System.out.println(label.getText());
    });

    tabbedPane.setPreferredSize(new Dimension(500, 300));

    JFrame frame = new JFrame();
    frame.getContentPane().add(tabbedPane);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JPanel panel = new JPanel();
    Box box = Box.createVerticalBox();
    for (int i = 0; i < 100; i++) {
        box.add(new JLabel("Hello!"));
    }/*  w  w w  . ja va2  s . c om*/
    panel.add(box);

    JTabbedPane tab = new JTabbedPane();
    JScrollPane scroll = new JScrollPane(panel);
    scroll.setPreferredSize(new Dimension(300, 300));
    tab.add(scroll, "Panel 1");

    JOptionPane.showMessageDialog(null, tab, "Test Tabbed", JOptionPane.PLAIN_MESSAGE);
}

From source file:TabbedPaneTest.java

public static void main(String args[]) {
    JFrame frame = new JFrame("JTabbedPane");
    final Container contentPane = frame.getContentPane();
    JTabbedPane jtp = new JTabbedPane();
    contentPane.add(jtp, BorderLayout.CENTER);
    for (int i = 0; i < 5; i++) {
        JButton button = new JButton("Card " + i);
        jtp.add("Btn " + i, button);
    }/*  w  ww .  ja  va  2 s.c  o  m*/
    frame.setSize(300, 200);
    frame.show();
}