import javax.swing.JTabbedPane;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.*;
import java.awt.event.*;
public class JTabbedPaneDemo extends JPanel {
public JTabbedPaneDemo() {
JTabbedPane tabed = new JTabbedPane();
JPanel Panel1 = createInnerPanel("Tab 1 Contains Tooltip and Icon");
tabed.addTab("One",Panel1);
tabed.setSelectedIndex(0);
JPanel Panel2 = createInnerPanel("Tab 2 Contains Icon only");
tabed.addTab("Two", Panel2);
JPanel Panel3 = createInnerPanel("Tab 3 Contains Tooltip and Icon");
tabed.addTab("Three", Panel3);
JPanel Panel4 = createInnerPanel("Tab 4 Contains Text only");
tabed.addTab("Four", Panel4);
// Add the tabbed pane to this panel.
setLayout(new GridLayout(1, 1));
add(tabed);
}
protected JPanel createInnerPanel(String text) {
JPanel Panel = new JPanel();
JLabel Display = new JLabel(text);
Display.setHorizontalAlignment(JLabel.CENTER);
Panel.setLayout(new GridLayout(1, 1));
Panel.add(Display);
return Panel;
}
public static void main(String[] args) {
JFrame frame = new JFrame("TabbedPane Source Demo");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.getContentPane().add(new JTabbedPaneDemo(),
BorderLayout.CENTER);
frame.setSize(400, 300);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
}
}
Hasilnya :
Tidak ada komentar:
Posting Komentar