OnJava8-Examples/gui/TabbedPane1.java

31 lines
897 B
Java
Raw Normal View History

2015-04-20 15:36:01 -07:00
//: gui/TabbedPane1.java
2015-05-29 14:18:51 -07:00
// <20>2015 MindView LLC: see Copyright.txt
2015-04-20 15:36:01 -07:00
// Demonstrates the Tabbed Pane.
import javax.swing.*;
import java.awt.*;
import static net.mindview.util.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++));
2015-05-06 12:09:38 -07:00
tabs.addChangeListener(e ->
2015-05-05 14:05:39 -07:00
txt.setText("Tab selected: " +
2015-05-06 12:09:38 -07:00
tabs.getSelectedIndex()));
2015-04-20 15:36:01 -07:00
add(BorderLayout.SOUTH, txt);
add(tabs);
}
public static void main(String[] args) {
run(new TabbedPane1(), 400, 250);
}
} ///:~