• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

enalbe, disable checkboxes

 
Alex Teslin
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Is there a way to enable or disable checkboxes as you can do it for JButtons , such as this:

button1.setActionCommand("disable");
button1.setEnabled(false);

Then:

actionPerformed(ActionEvent e)
if("enable".equals(e.getActionCommand())) {
button1.setEnabled(true);
}

But when i try in checkBoxes like this:

itemStateChanged(ItemEvent e) {
if("enable".equals(e.getActionCommand())){}

it gives me an error:
cannot find symbol-method getActionCommand()

Which is not surprising because in ItemEvent class there is no getActionCommand() method.

But how can i use the same functionality as for JButtons?

Thank you
 
Ron McKenzie
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This should do about the same thing.
 
Alex Teslin
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which class getText() is in?

Compiler can not find it.

Thanks
 
Alex Teslin
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, but that returns the name of the JCheckBox.
How would i know if it is enabled or disabled?
Because i need to enable or disable depending on that
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ActionEvent class has a getActionCommand method. The ItemEvent class does not. However, both classes have access to their superclass (EventObject) method getSource which is used to get a reference to the component that generated the event. In the case of a class extending AbstractButton (JButton, JMenuItem and JToggleButton) there is also a getActionCommand method. JCheckBox extends from JToggleButton so it has access to the getActionCommand method of AbstractButton.
So how might this work?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic