• Post Reply Bookmark Topic Watch Topic
  • New Topic

setState() with JRadioButton  RSS feed

 
Dave Kairys
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the correct syntax similar to the following:
name_of_Jradiobutton_object.setState(either true or false), where name is the actual name of the control?
In code, I have jradbutton.setState(false) and it says that 'The method setState(boolean) is undefined for the type JRadioButton as the error in Eclipse.

Thanks!
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no "setState()" method. There's a "setSelected(boolean)" method which I think is what you're after.

Javadoc is your friend; see here.

I'm going to move this to our Swing/AWT/JFace/SWT forum for followup.
 
Rob Spoor
Sheriff
Posts: 20904
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also note that setSelected(false) does not deselect a radio button - to do that you have to select another radio button within the same button group. If you want to deselect all radio buttons you can create an invisible radio button which you then select.
 
Dave Kairys
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is what I am doing. That seems like more coding than necessary to achieve the desired outcome. I am more familiar with VB.NET and with that, all you have to do is code nameofcontrol.enabled(boolean).
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> nameofcontrol.enabled(boolean)

exactly the same in Java,
nameofcontrol.setEnabled(boolean)
however, the previous posts are referring to
setSelected(boolean)
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!