package com.clearlyspam23.GLE.debug; import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.EventQueue; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.border.EmptyBorder; public class CardLayoutTest extends JFrame implements ItemListener{ private JPanel contentPane; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { CardLayoutTest frame = new CardLayoutTest(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public CardLayoutTest() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 450, 300); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setLayout(new BorderLayout(0, 0)); setContentPane(contentPane); JPanel comboBoxPane = new JPanel(); //use FlowLayout String comboBoxItems[] = { BUTTONPANEL, TEXTPANEL }; JComboBox cb = new JComboBox(comboBoxItems); cb.setEditable(false); cb.addItemListener(this); comboBoxPane.add(cb); //Create the "cards". JPanel card1 = new JPanel(); card1.add(new JButton("Button 1")); card1.add(new JButton("Button 2")); card1.add(new JButton("Button 3")); JPanel card2 = new JPanel(); card2.add(new JTextField("TextField", 20)); //Create the panel that contains the "cards". cards = new JPanel(new CardLayout()); cards.add(card1, BUTTONPANEL); cards.add(card2, TEXTPANEL); contentPane.add(comboBoxPane, BorderLayout.PAGE_START); contentPane.add(cards, BorderLayout.CENTER); } JPanel cards; //a panel that uses CardLayout final static String BUTTONPANEL = "Card with JButtons"; final static String TEXTPANEL = "Card with JTextField"; // public void addComponentToPane(Container pane) { // //Put the JComboBox in a JPanel to get a nicer look. // // } public void itemStateChanged(ItemEvent evt) { CardLayout cl = (CardLayout)(cards.getLayout()); cl.show(cards, (String)evt.getItem()); } /** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event dispatch thread. */ // private static void createAndShowGUI() { // //Create and set up the window. // JFrame frame = new JFrame("CardLayoutDemo"); // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // // //Create and set up the content pane. // CardLayoutTest demo = new CardLayoutTest(); // demo.addComponentToPane(frame.getContentPane()); // // //Display the window. // frame.pack(); // frame.setVisible(true); // } }