Java Reference
In-Depth Information
JComboBox<String> cb = new JComboBox<>(comboBoxItems);
cb.setEditable(false);
cb.addItemListener(new ItemListener(){
@Override
public void itemStateChanged(ItemEvent evt) {
CardLayout cl = (CardLayout)(cardPanel.getLayout());
cl.show(cardPanel, (String)evt.getItem());
}
});
comboBoxPanel.add(cb);
frame.getContentPane().add(comboBoxPanel, BorderLayout.PAGE_START);
frame.getContentPane().add(cardPanel, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
}
}
2.
Run the project from Eclipse. You should see the window in Figure 11-15.
figure 11-15  
Search WWH ::




Custom Search