31 lines
878 B
Java
31 lines
878 B
Java
// ui/TabbedPane1.java
|
|
// ©2016 MindView LLC: see Copyright.txt
|
|
// Demonstrates the Tabbed Pane.
|
|
import javax.swing.*;
|
|
import java.awt.*;
|
|
import static onjava.SwingConsole.*;
|
|
|
|
public class TabbedPane1 extends JFrame {
|
|
private String[] flavors = {
|
|
"Chocolate", "Strawberry", "Vanilla Fudge Swirl",
|
|
"Mint Chip", "Mocha Almond Fudge", "Rum Raisin",
|
|
"Praline Cream", "Mud Pie"
|
|
};
|
|
private JTabbedPane tabs = new JTabbedPane();
|
|
private JTextField txt = new JTextField(20);
|
|
public TabbedPane1() {
|
|
int i = 0;
|
|
for(String flavor : flavors)
|
|
tabs.addTab(flavors[i],
|
|
new JButton("Tabbed pane " + i++));
|
|
tabs.addChangeListener(e ->
|
|
txt.setText("Tab selected: " +
|
|
tabs.getSelectedIndex()));
|
|
add(BorderLayout.SOUTH, txt);
|
|
add(tabs);
|
|
}
|
|
public static void main(String[] args) {
|
|
run(new TabbedPane1(), 400, 250);
|
|
}
|
|
}
|