This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes How to make a check on a radio button in Java code without using the Mouse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to make a check on a radio button in Java code without using the Mouse" Watch "How to make a check on a radio button in Java code without using the Mouse" New topic
Author

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

Tomas Reyes
Greenhorn

Joined: Jan 12, 2011
Posts: 6
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

Joined: Oct 27, 2005
Posts: 19685
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4531
    
    5

... or call clearSelection() of the ButtonGroup.


luck, db
There are no new questions, but there may be new answers.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19685
    
  20

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

Joined: May 03, 2008
Posts: 4531
    
    5

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

Joined: Oct 13, 2005
Posts: 38519
    
  23
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

Joined: Jan 12, 2011
Posts: 6
But how to specify the selected row in the setSelected is something like:


 
Consider Paul's rocket mass heater.
 
subject: How to make a check on a radio button in Java code without using the Mouse