GeeCON Prague 2014*
The moose likes Swing / AWT / SWT and the fly likes enalbe, disable checkboxes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "enalbe, disable checkboxes" Watch "enalbe, disable checkboxes" New topic

enalbe, disable checkboxes

Alex Teslin
Ranch Hand

Joined: Jan 16, 2006
Posts: 49

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



actionPerformed(ActionEvent e)
if("enable".equals(e.getActionCommand())) {

But when i try in checkBoxes like this:

itemStateChanged(ItemEvent e) {

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

Joined: Mar 15, 2006
Posts: 3
This should do about the same thing.
Alex Teslin
Ranch Hand

Joined: Jan 16, 2006
Posts: 49
Which class getText() is in?

Compiler can not find it.

Alex Teslin
Ranch Hand

Joined: Jan 16, 2006
Posts: 49
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

Joined: Jan 14, 2004
Posts: 1535
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?
It is sorta covered in the JavaRanch Style Guide.
subject: enalbe, disable checkboxes