Example usage for javax.swing JTabbedPane JTabbedPane

List of usage examples for javax.swing JTabbedPane JTabbedPane

Introduction

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

Prototype

public JTabbedPane() 

Source Link

Document

Creates an empty TabbedPane with a default tab placement of JTabbedPane.TOP.

Usage

From source file:MainClass.java

public static void main(String args[]) {
    JFrame f = new JFrame("JTabbedPane Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTabbedPane tabbedPane = new JTabbedPane();
    addIt(tabbedPane, "Tab One");
    addIt(tabbedPane, "Tab Two");
    addIt(tabbedPane, "Tab Three");
    f.add(tabbedPane, BorderLayout.CENTER);
    f.setSize(300, 200);/*  www  .j  a  va  2  s.  com*/
    f.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Tabbed Pane Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    String titles[] = { "General", "Security", "Content", "Connection", "Programs", "Advanced" };
    int mnemonic[] = { KeyEvent.VK_G, KeyEvent.VK_S, KeyEvent.VK_C, KeyEvent.VK_O, KeyEvent.VK_P,
            KeyEvent.VK_A };/*w  w  w.j  a va  2 s  .c  o  m*/
    for (int i = 0, n = titles.length; i < n; i++) {
        add(tabbedPane, titles[i], mnemonic[i]);
    }

    tabbedPane.removeAll();
    frame.add(tabbedPane, BorderLayout.CENTER);
    frame.setSize(400, 150);
    frame.setVisible(true);
}

From source file:TabSample.java

public static void main(String args[]) {

    JFrame frame = new JFrame("Tabbed Pane Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTabbedPane tabbedPane = new JTabbedPane();

    String titles[] = { "General", "Security", "Content", "Connection", "Programs", "Advanced" };
    int mnemonic[] = { KeyEvent.VK_G, KeyEvent.VK_S, KeyEvent.VK_C, KeyEvent.VK_O, KeyEvent.VK_P,
            KeyEvent.VK_A };/* w  ww. ja  v  a2s .  co  m*/
    for (int i = 0, n = titles.length; i < n; i++) {
        add(tabbedPane, titles[i], mnemonic[i]);
    }

    frame.add(tabbedPane, BorderLayout.CENTER);
    frame.setSize(400, 150);
    frame.setVisible(true);
}

From source file:TabLocation.java

public static void main(String args[]) {

    JFrame frame = new JFrame("Tabbed Pane Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTabbedPane tabbedPane = new JTabbedPane();

    String titles[] = { "General", "Security", "Content", "Connection", "Programs", "Advanced" };
    int mnemonic[] = { KeyEvent.VK_G, KeyEvent.VK_S, KeyEvent.VK_C, KeyEvent.VK_O, KeyEvent.VK_P,
            KeyEvent.VK_A };//from ww w .  j a  va  2s.  co  m
    for (int i = 0, n = titles.length; i < n; i++) {
        add(tabbedPane, titles[i], mnemonic[i]);
    }

    tabbedPane.setTabPlacement(JTabbedPane.BOTTOM);
    frame.add(tabbedPane, BorderLayout.CENTER);
    frame.setSize(400, 150);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JTabbedPane tabbedPane;/*from  w w  w  .  j  a v a 2  s  .c  o  m*/
    JTextField txtFoo = new JTextField(10);
    JPanel pnlFoo = new JPanel();
    pnlFoo.add(new JButton("Button 1"));
    pnlFoo.add(new JLabel("Foo"));
    pnlFoo.add(txtFoo);

    JTextField txtBar = new JTextField(10);
    JPanel pnlBar = new JPanel();
    pnlBar.add(new JButton("Button 3"));
    pnlBar.add(new JLabel("Bar"));
    pnlBar.add(txtBar);

    tabbedPane = new JTabbedPane();
    tabbedPane.addTab("Tab 1", pnlFoo);
    tabbedPane.addTab("Tab 2", pnlBar);

    tabbedPane.addChangeListener(e -> {
        Component comp = tabbedPane.getSelectedComponent();
        if (comp.equals(pnlFoo)) {
            txtFoo.requestFocusInWindow();
        } else if (comp.equals(pnlBar)) {
            txtBar.requestFocusInWindow();
        }
    });

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(460, 200);
    frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);
    frame.setVisible(true);

    txtFoo.requestFocusInWindow();
}

From source file:TabSample.java

public static void main(String args[]) {
    JFrame f = new JFrame("Got JTabbedPane?");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTabbedPane tabbedPane = new JTabbedPane();
    addIt(tabbedPane, "Tab One");
    addIt(tabbedPane, "Tab Two");
    addIt(tabbedPane, "Tab Three");
    addIt(tabbedPane, "Tab Four");
    addIt(tabbedPane, "Tab Five");
    f.add(tabbedPane, BorderLayout.CENTER);
    f.setSize(300, 200);/*ww  w .j  ava 2s.co m*/
    f.setVisible(true);

}

From source file:TabSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Tabbed Pane Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTabbedPane tabbedPane = new JTabbedPane();
    String titles[] = { "General", "Security", "Content", "Connection", "Programs", "Advanced" };
    int mnemonic[] = { KeyEvent.VK_G, KeyEvent.VK_S, KeyEvent.VK_C, KeyEvent.VK_O, KeyEvent.VK_P,
            KeyEvent.VK_A };//from   ww  w  .  ja  v a2  s .c  o m
    for (int i = 0, n = titles.length; i < n; i++) {
        add(tabbedPane, titles[i], mnemonic[i]);
        tabbedPane.setBackgroundAt(i, colors[i]);
    }
    frame.add(tabbedPane, BorderLayout.CENTER);
    frame.setSize(400, 150);
    frame.setVisible(true);
}

From source file:TabSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Tabbed Pane Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    String titles[] = { "A", "B", "C", "D", "E", "F" };
    for (int i = 0, n = titles.length; i < n; i++) {
        add(tabbedPane, titles[i]);//from w  ww. ja  v a 2  s . com
    }

    frame.add(tabbedPane, BorderLayout.CENTER);
    frame.setSize(400, 150);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JPanel panel = new JPanel() {
        @Override/*from   w w  w  .  j a  va  2s.c  o m*/
        public Dimension getPreferredSize() {
            return new Dimension(200, 200);
        }
    };
    panel.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e) {
            System.out.println("Resized to " + e.getComponent().getSize());
        }

        @Override
        public void componentMoved(ComponentEvent e) {
            System.out.println("Moved to " + e.getComponent().getLocation());
        }
    });
    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.addTab("test", panel);
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(tabbedPane);
    frame.pack();

    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);/*from  w  w  w. ja  v  a2  s  . c o m*/
    frame.setSize(500, 200);
    frame.setVisible(true);
}