Here's a quick example of handling a performed action.
Make sure to read through java tutorials before posting questions because lots of questions will probably already be answered:
http://java.sun.com/docs/books/tutor.../combobox.html
Code:
public class ComboDemo extends JPanel implements ActionListener{
public ComboDemo(){
String[] yesNo= {"YES","NO!"};
JComboBox comboBox = new JComboBox(yesNo);
comboBox.addActionListener(this);
add(comboBox);
}
public void actionPerformed(ActionEvent evt){
String selected;
JComboBox c = (JComboBox)evt.getSource();
selected = (String)c.getSelectedItem();
System.out.println("You selected: "+selected);
}
public static void createAndShowGUI(){
JFrame myFrame = new JFrame();
JPanel panel = new ComboDemo();
myFrame.add(panel);
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFrame.setSize(200, 100);
myFrame.setVisible(true);
}
public static void main(String args[]) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
Then you will change your components in the actionPerformed function based on the selected item.
eg. myComponent.setEditable(false);
Good luck
Bookmarks