• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

KeyBindings using KeyStroke  RSS feed

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote a keybinding into a program. The keybinding implementation that allowed me to use the ENTER key required me to use KeyStroke.getKeyStroke(int key, int modifier) as opposed to KeyStroke.getKeyStroke(String s). In both method calls, I used the appropriate key or modifier for ENTER, either KeyStroke.VK_ENTER or "Enter." Why does KeyStroke.getKeyStroke("Enter") not work?


 
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since this is related to Swing, I've added it to the GUIs section.

Have you tried ENTER instead of Enter?
 
Marshal
Posts: 59765
188
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know. Have a look at the Java™ Tutorials and the documentation for KeyStroke#getKeyStroke(). It says it takes an int and I think you will find those ints are stored as constants in the KeyEvent class. It is usual for constants to be written in CAPITAL_LETTERS, so that may be why you can't get "Enter" to work.

I see there is an overloaded version of KeyStroke#getKeyStroke() which takes a String parameter. It says there is a particular syntax you have to follow, so you may need to alter the String you were passing in the first version of the method to match that syntax. I think that "ENTER" probably would match the required syntax if you will accept “pressed”.
 
Aahan Agrawal
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"ENTER" as opposed to "Enter" resolved the issue.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!