aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Adding KeyStroke to JCheckBox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Adding KeyStroke to JCheckBox" Watch "Adding KeyStroke to JCheckBox" New topic
Author

Adding KeyStroke to JCheckBox

Lubomir Kolacik
Greenhorn

Joined: May 06, 2012
Posts: 8
I want to add KeyStrokes to group of CheckBoxes ,so when user hits 1 on keyboard,then first JCheckBox. will be selected / deselected .

I have made this part of code ,but its not working, can somebody point me into correct direction? ( I can also put action creating outside the loop , nothing change )

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

Casting an int to a char doesn't turn it into the matching char. For instance, (char) 9 is not the character '9' but a tab character instead; see http://www.asciitable.com/.
To convert an int into the matching char, use Character.forDigit.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Lubomir Kolacik
Greenhorn

Joined: May 06, 2012
Posts: 8
Rob Spoor wrote:Casting an int to a char doesn't turn it into the matching char. For instance, (char) 9 is not the character '9' but a tab character instead; see http://www.asciitable.com/.
To convert an int into the matching char, use Character.forDigit.


Thanks, its true ,so I remade it into : (char)('0'+i) , but its still not working.

I was thinking about focus , but if there use WHEN_IN_FOCUSED_WINDOW it should not matter then?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
try removing the 'true'
 
 
subject: Adding KeyStroke to JCheckBox
 
Similar Threads
JTabbedPane with Keyevents
About Keybinding
searching JFrame
Problem in checkbox
HELLP! i cant get 2 JPanels to display without them sitting on the other!