• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to make a check on a radio button in Java code without using the Mouse

 
Tomas Reyes
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created a JTable and add a radio button. After I created another JTable when I click on the string of one row
I have to select and check on the radio button of the initial JTable, and found the radio button but I am not
shure what property or method allows me to check the radio button without using the mouse.
My code is:


Thanks in advance
Tomas
 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the setSelected method.

Note that calling setSelected(false) will not uncheck a radio button. To do that, the usual trick is to add a radio button to the same button group but not add it to the user interface. When you select this invisible radio button all other radio buttons are unselected.
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... or call clearSelection() of the ButtonGroup.
 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:... or call clearSelection() of the ButtonGroup.

Cool, this method was really needed. I didn't know they added it in Java 6.
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:
Darryl Burke wrote:... or call clearSelection() of the ButtonGroup.

Cool, this method was really needed. I didn't know they added it in Java 6.


I only came to Java after 6 was released, so it's maybe easier for me ;)
 
Campbell Ritchie
Sheriff
Pie
Posts: 49808
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are 4072 (I think) classes in Java7, and some have hundreds of methods, so you can’t expect people to know about every method.
 
Tomas Reyes
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But how to specify the selected row in the setSelected is something like:


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic