Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Button with key shortcut

  Asked By: Howard    Date: Jul 05    Category: Java    Views: 9359
  

we can simply add & to Button caption so that the
letter following the & will be regarded as shortcut key for the Button.
In, Java how to do the same thing that is the letter in the Button will
be underlined and the letter will be considered as shortcut for the
Button event.

Share: 

 

5 Answers Found

 
Answer #1    Answered By: Nixie Schmidt     Answered On: Jul 05

Try:
myJButton.setMnemonic('b');

This is assuming you are in swing and using JButtons of course. Probably will
work with AWT heavyweight buttons. This setMnemonic method will allow you to
hit "ALT + B" and the button  will think it got clicked.

 
Answer #2    Answered By: Isabelle Brown     Answered On: Jul 05

And do you have any idea how to add  underline to one of the letters of
JButton text ? This is applicable to inform the user that he could use
Alt + underlined_letter instead of clicking the button.

 
Answer #3    Answered By: Nagaraju Iyaner     Answered On: Jul 05

And do you have any idea how to add  underline to one of the letters of
JButton text ? This is applicable to inform the user that he could use
Alt + underlined_letter instead of clicking the button.

 
Answer #4    Answered By: Tyrone Sanchez     Answered On: Jul 05

When you use the underlined letter to show that you can use alt-key as a
shortcut, the menu item has to be visible for the user to do so. It is better
to have ctrl-key shortcuts to the side of the menu item. Often, by the time
someone finds what they are looking for, they might as well move the mouse to it
as to find it then hit the alt-key combination.

 
Answer #5    Answered By: Jonathan Brown     Answered On: Jul 05

Sorry, yes it works. I failed to notice that before.
Thank's for your help.

 
Didn't find what you were looking for? Find more on Button with key shortcut Or get search suggestion and latest updates.




Tagged: