JTabbedPane.SCROLL_TAB_LAYOUT : JTabbedPane « javax.swing « Java by API






JTabbedPane.SCROLL_TAB_LAYOUT

 

import java.awt.BorderLayout;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;

public class Main {

  static void add(JTabbedPane tabbedPane, String label, int mnemonic) {
    int count = tabbedPane.getTabCount();
    JButton button = new JButton(label);
    tabbedPane.addTab(label, new ImageIcon("yourFile.gif"), button, label);
    tabbedPane.setMnemonicAt(count, mnemonic);
  }

  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 };
    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);
  }
}

   
  








Related examples in the same category

1.JTabbedPane: addChangeListener(ChangeListener l)
2.JTabbedPane: addTab(String title, Component component)
3.JTabbedPane: addTab(String title, Icon icon, Component component, String tip)
4.JTabbedPane: getComponentAt(int index)
5.JTabbedPane: getDisabledIconAt(int index)
6.JTabbedPane: getDisplayedMnemonicIndexAt(int tabIndex)
7.JTabbedPane: getIconAt(int index)
8.JTabbedPane: getMnemonicAt(int tabIndex)
9.JTabbedPane: getTitleAt(int index)
10.JTabbedPane: getToolTipTextAt(int index)
11.JTabbedPane: indexOfComponent(Component component)
12.JTabbedPane: indexOfTab(String title)
13.JTabbedPane: insertTab(String title, Icon icon, Component component, String tip, int index)
14.JTabbedPane: isEnabledAt(int index)
15.JTabbedPane: remove(Component component)
16.JTabbedPane: removeAll()
17.JTabbedPane: removeTabAt(int index)
18.JTabbedPane: setBackgroundAt(int index, Color background)
19.JTabbedPane: setDisabledIconAt(int index, Icon disabledIcon)
20.JTabbedPane: setDisplayedMnemonicIndexAt(int tabIndex, int mnemonicIndex)
21.JTabbedPane: setEnabledAt(int index, boolean enabled)
22.JTabbedPane: setForegroundAt(int index, Color foreground)
23.JTabbedPane: setMnemonicAt(int tabIndex, int mnemonic)
24.JTabbedPane: setSelectedIndex(int index)
25.JTabbedPane: setTabComponentAt(int index, Component component)
26.JTabbedPane: setTabLayoutPolicy(int tabLayoutPolicy)
27.JTabbedPane: setTabPlacement(int tabPlacement)
28.JTabbedPane: setToolTipTextAt(int index, String toolTipText)