• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Mnemonics in JDialog

 
Greenhorn
Posts: 13
Eclipse IDE Chrome Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone.
I am working on a JDialog for an application I am developing. I want to use mnemonics with my buttons but without having to press Alt for them to come up. Does anyone have a solution to this?
(I would use a KeyListener but I want the letter on the button underlined as well, without pressing Alt)

Here is my code so far (code involving the buttons anyway)...

 
Ranch Hand
Posts: 530
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi folk, I am afraid that you cannot change the way mnemonics work, as it always associate with the Alt key.
If you really want to use one key, consider using hot key.
 
Rancher
Posts: 3324
32
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

but I want the letter on the button underlined as well, without pressing Alt)



Pressing the Alt is a well defined standard for invoking a button. MS and other companies have spend millions of dollars developing a common UI for Users to use and understand. I don't know why you would try to change this practice.

I would use a KeyListener



Using a KeyListener is not the proper way to attempt to do this. If you really want to go againt all conventions then instead you need to use Key Bindings. Read the section from the Swing tutorial on How To Use Key Bindings. Then it would be a 2 step process:

1) You still have to do what you are doing, that is set the mnemonic so that the letter is underlined
2) Create the key binding using the same Action.

Now the user will have the choice of using either approach.
 
catch it before it slithers away! Oh wait, it's a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic