File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes setMnemonic() not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "setMnemonic() not working" Watch "setMnemonic() not working" New topic

setMnemonic() not working

Vidur Koushik

Joined: May 07, 2012
Posts: 16
I have written a small program..this is the example program shown in the official tutorials(uiswing) on oracle website..
i only made some minor changes..but somehow setMnemonic() is not working..
Can somebody please point out my mistake..
Here's My code..

Thank You.
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

My guess is that KeyEvent.VK_B represents "b" and you're expecting the setMnemonic method to make that apply to a different letter, namely "B".

Edit: No, that's wrong. The documentation says that setMnemonic is case-insensitive. So, what makes you think it isn't working?
Keshan Pillay

Joined: May 21, 2008
Posts: 29
I believe I've read before (I'll try and look it up to cite this) that with Jbuttons you set the mnemonic but you need to access it with the 'ALT' key.
So try 'ALT + B' etc. Let me know.

I cant find the documentation however...


This is a little SSCCE example from the website which is a JButton with the Mnemonic 'A' set to it. Indeed, if you press 'A' nothing happens
however if you try 'Alt + A' then the button is pressed.
Vidur Koushik

Joined: May 07, 2012
Posts: 16
Thank You @@Keshan Pillay and @@Paul Clapham
I realized that we have to press "ALT+B".
and it that is the way it works.

Thanks once again for your replies.
I agree. Here's the link:
subject: setMnemonic() not working
It's not a secret anymore!