Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
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
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Swing / AWT / SWT
Bind jbutton event to a keystroke
Kasun Wixkramanayake
Ranch Hand
Posts: 74
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
KeyStroke enter = KeyStroke.getKeyStroke("control alt 7"); InputMap inputMap = jButton1.getInputMap(); ActionMap actionMap = jButton1.getActionMap(); inputMap = jButton1.getInputMap(); inputMap.put(enter, ACTION_KEY); jButton1.setActionMap(actionMap); private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { System.out.print("It Works"); }
i need to bind a jbutton event to a keystroke.so i use above code to do that.but it didnt work(I use netbeans 6.9 ).please help me
Paul Clapham
Marshal
Posts: 28193
95
I like...
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I would say you would be better off creating an Action, and then binding both the JButton and the keystroke to that Action.
Darryl Burke
Bartender
Posts: 5167
11
I like...
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Sorry, but that code is pretty meaningless. Lines 3 and 5 perform an identical assignment, and line 7 sets the same ActionMap that has just been retrieved. Whayt would you expect that to accomplish?
Recommended reading:
How to Use Key Bindings
luck, db
There are no new questions, but there may be new answers.
yeah, but ... what would PIE do? Especially concerning this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Using ActionMap for HotKey mapping
About Keybinding
NX: How to register a key event to a frame
doing same job on two or more events
getting KeyPressed for JDialog? example?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
More...