import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;
public class TabSampleTabLayoutPolicy {
static void add(JTabbedPane tabbedPane, String label) {
JButton button = new JButton(label);
tabbedPane.addTab(label, button);
}
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]);
}
frame.add(tabbedPane, BorderLayout.CENTER);
frame.setSize(400, 150);
frame.setVisible(true);
}
}
|