Example usage for javax.swing JTabbedPane addTab

List of usage examples for javax.swing JTabbedPane addTab

Introduction

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

Prototype

public void addTab(String title, Component component) 

Source Link

Document

Adds a component represented by a title and no icon.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    JTabbedPane pane = new JTabbedPane();
    pane.setUI(new SpacedTabbedPaneUI());
    pane.addTab("One", new JPanel());
    pane.addTab("Two", new JPanel());
    pane.addTab("Threeeeeee", new JPanel());
    pane.addTab("Four", new JPanel());

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(pane);/*from  w  w  w.  j  av a2s .  c  o m*/
    frame.setSize(500, 200);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JTabbedPane pane = new JTabbedPane();
    JButton component = new JButton("button");

    String label = "Tab Label";
    pane.addTab(label, component);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JTabbedPane pane = new JTabbedPane();
    pane.setForeground(Color.YELLOW);
    pane.setBackground(Color.MAGENTA);
    String label = "Tab Label";
    pane.addTab(label, new JButton("Button"));

    int index = pane.getTabCount() - 1;

    pane.setForegroundAt(index, Color.ORANGE);
    pane.setBackgroundAt(index, Color.GREEN);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setResizable(false);/* w w  w  . j a  v  a2 s.  c o m*/
    JTabbedPane tabs = new JTabbedPane();
    tabs.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    for (int i = 0; i < 5; i++) {
        tabs.addTab("Tab" + i, new TabPanel());
    }

    frame.add(tabs);
    frame.pack();
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String[] args) {
    Container c1 = new GradientPanel();
    Container c2 = new GradientPanel();
    JTabbedPane top = new JTabbedPane();

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    top = new JTabbedPane(JTabbedPane.TOP);
    top.addTab("1", c1);
    top.addTab("2", c2);
    frame.add(top);/* w ww . j  a  v a2s .  c o  m*/
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static final void main(String[] args) {
    JFrame frame = new JFrame();
    JTabbedPane tabbedPane = new JTabbedPane();

    frame.add(tabbedPane);//from  w w w . j a v a2  s .  c om

    JButton addButton = new JButton("Add tab");
    addButton.addActionListener(e -> {
        JPanel newTabComponent = new JPanel();
        int tabCount = tabbedPane.getTabCount();
        newTabComponent.add(new JLabel("I'm tab " + tabCount));
        tabbedPane.addTab("Tab " + tabCount, newTabComponent);
    });
    frame.add(addButton, BorderLayout.SOUTH);
    addButton.doClick();

    frame.setSize(800, 300);
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.setUI(new MetalTabbedPaneUI() {
        @Override/*from w w  w.  j  av a 2  s. co m*/
        protected int calculateTabWidth(int tabPlacement, int tabIndex, FontMetrics metrics) {
            int width = super.calculateTabWidth(tabPlacement, tabIndex, metrics);
            int extra = tabIndex * 50;
            return width + extra;
        }
    });
    tabbedPane.addTab("JTable", new JScrollPane(new JTable(5, 5)));
    tabbedPane.addTab("JTree", new JScrollPane(new JTree()));
    tabbedPane.addTab("JSplitPane", new JSplitPane());

    JPanel p = new JPanel();
    p.add(tabbedPane);

    JFrame frame = new JFrame();
    frame.setContentPane(p);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

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

    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:ShowComponent.java

public static void main(String[] args) {
    // Process the command line to get the components to display
    Vector components = getComponentsFromArgs(args);

    // Create a frame (a window) to display them in
    JFrame frame = new JFrame("ShowComponent");

    // Handle window close requests by exiting the VM
    frame.addWindowListener(new WindowAdapter() { // Anonymous inner class
        public void windowClosing(WindowEvent e) {
            System.exit(0);//from w w  w  . jav a2  s . c o m
        }
    });

    // Set up a menu system that allows the user to select the
    // look-and-feel of the component from a list of installed PLAFs
    JMenuBar menubar = new JMenuBar(); // Create a menubar
    frame.setJMenuBar(menubar); // Tell the frame to display it
    JMenu plafmenu = createPlafMenu(frame); // Create a menu
    menubar.add(plafmenu); // Add the menu to the menubar

    // Create a JTabbedPane to display each of the components
    JTabbedPane pane = new JTabbedPane();

    // Now add each component as a tab of the tabbed pane
    // Use the unqualified component classname as the tab text
    for (int i = 0; i < components.size(); i++) {
        Component c = (Component) components.elementAt(i);
        String classname = c.getClass().getName();
        String tabname = classname.substring(classname.lastIndexOf('.') + 1);
        pane.addTab(tabname, c);
    }

    // Add the tabbed pane to the frame. Note the call to getContentPane()
    // This is required for JFrame, but not for most Swing components
    frame.getContentPane().add(pane);

    // Set the frame size and pop it up
    frame.pack(); // Make frame as big as its kids need
    frame.setVisible(true); // Make the frame visible on the screen

    // The main() method exits now but the Java VM keeps running because
    // all AWT programs automatically start an event-handling thread.
}

From source file:TabSampleTabLayoutPolicy.java

static void add(JTabbedPane tabbedPane, String label) {
    JButton button = new JButton(label);
    tabbedPane.addTab(label, button);
}