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
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: 19723
    
  20

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'
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Adding KeyStroke to JCheckBox