activate and deactivate ComboBox

Posted by Jessy on Stack Overflow See other posts from Stack Overflow or by Jessy
Published on 2010-03-31T11:41:08Z Indexed on 2010/03/31 11:43 UTC
Read the original article Hit count: 377

Filed under:
|
|

How can I make the comboBox available when the checkBox was uncheck (vice versa)

Why the comboBox is still disable after I unChecked the checkBox?

choice [] = {"A","B","C"};
JComboBox a = new JComboBox(choice);

JCheckBox chk = new JCheckBox("choice");

...
a.addActionListener(this);
chk.addActionListener(this);
...

public void actionPerformed(ActionEvent e) {

   //disable the a comboBox when the checkBox chk was checked
  if(e.getSource()==chk)
    a.setEnabled(false);

  //enable the a comboBox when the checkBox chk was unchecked
  else if(e.getSource()!=chk)
    a.setEnabled(true);
}

© Stack Overflow or respective owner

Related posts about java

Related posts about checkbox