Please refer following example of java , which will depict you the use of JTabbedPane class:
Code:
import javax.swing.JTabbedPane;
public class JTabbedPaneDemo {
static void add(JTabbedPane TBP, String lb, int mnemonic) {
int count = TBP.getTabCount();
JButton button = new JButton(lb);
TBP.addTab(lb, new ImageIcon("yourFile.gif"), button, lb);
TBP.setMnemonicAt(count, mnemonic);
}
public static void main(String args[]) {
JFrame fmj = new JFrame("Tabbed Pane Sample");
fmj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTabbedPane TBP = new JTabbedPane();
TBP.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(TBP, titles[i], mnemonic[i]);
}
TBP.removeAll();
fmj.add(TBP, BorderLayout.CENTER);
fmj.setSize(500, 150);
fmj.setVisible(true);
}
}
Bookmarks