• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

enalbe, disable checkboxes

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This should do about the same thing.
 
Alex Teslin
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic