Example usage for javax.swing JTabbedPane SCROLL_TAB_LAYOUT

List of usage examples for javax.swing JTabbedPane SCROLL_TAB_LAYOUT

Introduction

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

Prototype

int SCROLL_TAB_LAYOUT

To view the source code for javax.swing JTabbedPane SCROLL_TAB_LAYOUT.

Click Source Link

Document

Tab layout policy for providing a subset of available tabs when all the tabs will not fit within a single run.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JTabbedPane pane = new JTabbedPane();
    int rows = pane.getTabRunCount();

    int policy = pane.getTabLayoutPolicy(); // WRAP_TAB_LAYOUT

    pane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);

}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

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

    ChangeListener changeListener = new ChangeListener() {
        public void stateChanged(ChangeEvent changeEvent) {
            JTabbedPane sourceTabbedPane = (JTabbedPane) changeEvent.getSource();
            int index = sourceTabbedPane.getSelectedIndex();
            System.out.println("Tab changed to: " + sourceTabbedPane.getTitleAt(index));
        }
    };
    tabbedPane.addChangeListener(changeListener);

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

}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setResizable(false);//from w w w .  jav a 2s.co  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:TabSampleTabLayoutPolicy.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" };
    for (int i = 0, n = titles.length; i < n; i++) {
        add(tabbedPane, titles[i]);//ww w  .  j a va2s.c  om
    }

    frame.add(tabbedPane, BorderLayout.CENTER);
    frame.setSize(400, 150);
    frame.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 };//from   www . j a va  2s  .  co 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();
    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]);/*w  w  w.j ava 2  s. c o  m*/
    }

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

From source file:Main.java

public JComponent makeUI() {
    JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
    tabbedPane.setUI(new javax.swing.plaf.basic.BasicTabbedPaneUI() {
        @Override/* ww w.  j  a  va 2s  .  c o  m*/
        protected int calculateTabHeight(int tabPlacement, int tabIndex, int fontHeight) {
            return 32;
        }

        @Override
        protected void paintTab(Graphics g, int tabPlacement, Rectangle[] rects, int tabIndex,
                Rectangle iconRect, Rectangle textRect) {
            if (tabIndex == 0) {
                rects[tabIndex].height = 30 + 1;
                rects[tabIndex].y = 32 - rects[tabIndex].height + 1;
            } else if (tabIndex == 1) {
                rects[tabIndex].height = 26 + 1;
                rects[tabIndex].y = 32 - rects[tabIndex].height + 1;
            }
            super.paintTab(g, tabPlacement, rects, tabIndex, iconRect, textRect);
        }
    });
    tabbedPane.addTab("000", new JLabel("ok"));
    tabbedPane.addTab("111", new JScrollPane(new JTable()));
    tabbedPane.addTab("222", new JSplitPane());

    return tabbedPane;
}

From source file:TooManyTabs.java

public TooManyTabs() {
    super("Too Many Tabs Test");
    setSize(200, 200);/*from  w w w .j  a v a2s .c o m*/
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    Container contents = getContentPane();

    JTabbedPane wrap = new JTabbedPane();
    JTabbedPane scroll = new JTabbedPane();
    scroll.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    for (int i = 1; i < 24; i++) {
        String tab = "Tab #" + i;
        wrap.addTab(tab, new JLabel(tab));
        scroll.addTab(tab, new JLabel(tab));
    }
    JTabbedPane top = new JTabbedPane(JTabbedPane.RIGHT);
    top.addTab("Wrap Tabs", wrap);
    top.addTab("Scroll Tabs", scroll);
    contents.add(top);

    setVisible(true);
}

From source file:Main.java

public Main() {
    tabbedPane.addTab("Tab1", label1);
    tabbedPane.addTab("Tab2", label2);
    tabbedPane.addTab("Tab3", label3);
    tabbedPane.addTab("Tab4", label4);
    tabbedPane.setTabPlacement(JTabbedPane.TOP);
    tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);

    label1.addAncestorListener(new EventHandler());
    label2.addAncestorListener(new EventHandler());
    label3.addAncestorListener(new EventHandler());
    label4.addAncestorListener(new EventHandler());

    label1.addHierarchyListener(new EventHandler());
    label2.addHierarchyListener(new EventHandler());
    label3.addHierarchyListener(new EventHandler());
    label4.addAncestorListener(new EventHandler());

    label1.addComponentListener(new EventHandler());
    label2.addComponentListener(new EventHandler());
    label3.addComponentListener(new EventHandler());
    label4.addComponentListener(new EventHandler());

    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(tabbedPane, BorderLayout.CENTER);
    f.setPreferredSize(new Dimension(600, 400));
    f.pack();/*from w  ww. j  a  v  a 2s.  co  m*/
    f.setVisible(true);
}

From source file:Main.java

public Main() {
    super(new GridLayout(1, 1));

    JTabbedPane tabbedPane = new JTabbedPane();
    ImageIcon icon = createImageIcon("images/middle.gif");

    JComponent panel1 = makeTextPanel("Panel #1");
    tabbedPane.addTab("Tab 1", icon, panel1, "Does nothing");
    tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);

    JComponent panel2 = makeTextPanel("Panel #2");
    tabbedPane.addTab("Tab 2", icon, panel2, "Does twice as much nothing");
    tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);

    JComponent panel3 = makeTextPanel("Panel #3");
    tabbedPane.addTab("Tab 3", icon, panel3, "Still does nothing");
    tabbedPane.setMnemonicAt(2, KeyEvent.VK_3);

    JComponent panel4 = makeTextPanel("Panel #4 (has a preferred size of 410 x 50).");
    panel4.setPreferredSize(new Dimension(410, 50));
    tabbedPane.addTab("Tab 4", icon, panel4, "Does nothing at all");
    tabbedPane.setMnemonicAt(3, KeyEvent.VK_4);

    add(tabbedPane);/*from   w  w  w .  j ava 2s  .  c  om*/

    tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
}