• Post Reply Bookmark Topic Watch Topic
  • New Topic

keyboard equivalent for buttons

 
Sumner Khloe
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This seems like it would be a simple thing to do but after searching I couldn't find the solution I was looking for.

I would like to set keys on the keyboard to be the equivalent as pressing certain JButtons in my application. Could somebody help me out? Thanks.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are you using for your UI?
Swing/SWT/HTML?
 
Sumner Khloe
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Swing.
 
Sumner Khloe
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you! This looks like just what I need.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swing related.
Moving to the correct forum.
 
Sumner Khloe
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I have to use an Action Object for what is invoked in the actionMap? They seem kind of complicated. Is there any way I could use an ActionListener instead of Action? Do you get what I mean? If it sounds like I am just trying to sidestep the work, I am. But really I just want a buttons action message to be fired to its action listeners whenever a key is pressed.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You got two options.
1) Implement AbstractAction and share it between the actionMap and the button.
2) Setup your buttons with their listeners in the usual way. In the action map provide an action which in turn will programmatically click the desired button.

PS. If it is OK with your requirement, you can define the mnemonics for the buttons. Of course that would work only with the associated key like the Alt key on windows.
 
Sumner Khloe
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankyou Maneesh, once again you've been a great help. I think I will go with the second option.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!