setMnemonic for non-english characters

Does anybody knos how to set JButtons mnemonic for non-english characters?

My mnemonic is loaded from a resource bundle, and in the documentation the setMnemonic(char) is only limited to english and it is written that the user should call setMnemonic(int) instead.

So what value should this int contains in order to display the non-english char which is loaded from resource bundle?

Thanks in advanve,

Hanoch

[439 byte] By [hanoch_ya] at [2007-10-1 19:12:00]
# 1
The API documentation explains that. Can you be more specific about what part of the explanation you are having trouble with?
DrClapa at 2007-7-11 14:38:15 > top of Java-index,Desktop,I18N...
# 2

I hope the originator doesn't mind if I admit that I do have a question related to the API...

I have to admit that I am a little confused about this part of the explanation:

"A mnemonic must correspond to a single key on the keyboard and should be specified using one of the VK_XXX keycodes defined in java.awt.event.KeyEvent"

Doesn't that mean that if we want to read the value of a mnemonic from a resource bundle we will have to create an integer for the corresponding KeyEvent from the character specified in the bundle? The method seems well suited for hardcoded mnemonics, but not so well enabled for localization - unless I have completely misunderstood something... which I readily admit I may have.

one_danea at 2007-7-11 14:38:15 > top of Java-index,Desktop,I18N...
# 3

It looks to me like the people who wrote that documentation assumed you were going to dosetMnemonic(java.awt.event.KeyEvent.VK_F11)

or something like that. So yes, to put that into a ResourceBundle you would have to find out that the VK_F11 constant is equal to 122, and put that number into the bundle.

(To find that out, click on the VK_F11 link in the documentation and then click on the "Constant Field Values" link in the page that takes you to.)

I would agree exactly with your opinion.

DrClapa at 2007-7-11 14:38:15 > top of Java-index,Desktop,I18N...
# 4

It seems that this is an issue that has popped up in various forums before, here's one example from last year:

http://forum.java.sun.com/thread.jspa?forumID=16&threadID=490722

This entry has some suggestions for handling mnemonics in resource bundles, and they would take care of translated mnemonics - as long as the translated values are restricted to the values contained in the VK_XXX keycodes.

And since those values are basically the English (ASCII) character set + a bunch of function keys, it doesn't solve the original problem - how to specify mnemonics that are not part of the English character set. The more I look at this I don't really understand the reason for making setMnemonic (char mnemonic) obsolete and making setMnemonic (int mnemonic) the default. If anything this has made the method more difficult to use.

I also don't understand the statement in the API about setMnemonic (char mnemonic):

"This method is only designed to handle character values which fall between 'a' and 'z' or 'A' and 'Z'."

If the type is "char", why would the character values be restricted to values between 'a' and 'z' or 'A' and 'Z'? I understand the need for the value to be restricted to one keystroke (eliminating the possibility of using ideographic characters), but why make it impossible to use all the Latin-1 and Latin-2 characters, for instance? (and is that in fact the case?) It is established practice on other platforms to be able to use characters such as '?, '? and '?, for instance.

And if changes were made, why not enable the simple way of specifying a mnemonic that other platforms have implemented, by adding an '&' in front of the character?

Sorry if this disintegrated into a rant - didn't mean to... :-) I'm sure there must be good reasons for the changes, would love to understand them.

one_danea at 2007-7-11 14:38:15 > top of Java-index,Desktop,I18N...
# 5

Ok, I think I found answers to my questions:

First of all, there's a really old bug report with the following evaluation:

"Mnemonics and Keyboard Accelerators are pretty much useless for non-English languages. The current API is not powerful enough to allow fixing this problem. This bug should be addressed in the merlin feature release."

(http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4239028)

This was opened in 1999, but the state is still "in progress", and the following update from 2004 does not provide much hope:

"Note: The setMnemonic(char) method is obsolete and has been replaced with setMnemonic(int) which takes a VK code. However, this still may not be powerful enough for non-English languages."

What beats me is why anybody would think that setMnemonic(int) would be any improvement whatsoever - since the VK codes do not contain non-English characters!

Anyway, I also found a statement which may explain why this is still not fixed: Java keyboard input is defined as part of awt, and therefore platform dependent. The keys are mapped according to the latin layer of keyboards, and therefore _may_ work for non-English characters in Latin-based European languages, but not for e.g. Russian, Greek, etc. And only _documented_ to work for a-z, A-Z.

one_danea at 2007-7-11 14:38:15 > top of Java-index,Desktop,I18N...