• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

URLyBird Menu Mnemonics

 
Rob Pearson
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I was just starting to put together the GUI for my assignment and have set up a properties file to read all strings, labels, messages etc from (actually a ResourceBundle, bit OTT???)
Anyway, I was trying to set the mnemonic (keyboard short cut) on a JMenu using setMnemonic, but this only seems to accept a KeyEvent.VK_* (since the setMnemonic method that accepts a char is marked as obsolete). So my question is, how do I set the mnemonic on a menu without hardcoding the key (or using obsolete methods - which is probably not a good thing to do in an assignment).
BTW I just came accross the Ranch a few weeks ago - looks like there's some good stuff here. Keep it up.
Cheers
Rob
 
Ta Ri Ki Sun
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Pearson:
Hi,
I was just starting to put together the GUI for my assignment and have set up a properties file to read all strings, labels, messages etc from (actually a ResourceBundle, bit OTT???)

not at all OTT

Anyway, I was trying to set the mnemonic (keyboard short cut) on a JMenu using setMnemonic, but this only seems to accept a KeyEvent.VK_* (since the setMnemonic method that accepts a char is marked as obsolete). So my question is, how do I set the mnemonic on a menu without hardcoding the key (or using obsolete methods - which is probably not a good thing to do in an assignment).
BTW I just came accross the Ranch a few weeks ago - looks like there's some good stuff here. Keep it up.
Cheers
Rob

I'm not sure I understand what the problem is here, but anyhat if you meant you dont want to use the KeyEvent constants, then you could use int's in your props file, or having a method fetch one from a util class given the resource key, and I'm sure even thats overkill, and unless I misunderstood you I dont see the point to such a solution, care to explain the problem a little differently please?
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob,
Welcome to JavaRanch.
I notice that setMnemonic(char) is only marked as obsolete, not deprecated, so you could probably use it without problems.
Alternatively (although more work for you), you could allow the mnemonic to be entered in the resource bundle as either a char or an int. And you have the option of allowing the user to enter an int value if they cannot type the char value.
If you are really worried about using the char value (I wouldn't be - it is not deprecated), convert the lower case equivalent of the char to an int, and use that value. It should always work, and you can note in your documentation that you allow an int value to be specified directly if the character specified does not display correctly.
I think that both my options might be good for real life applications, but may be going overboard for the scope of this assignment.
Regards, Andrew
 
Rob Pearson
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its not a big issue really, but I was planning on having something like this in my properties file:
menu.File.name = File
menu.File.mnemonic = F
The problem was how to use 'F' in a call to setMnemonic. Do I
1. Write something to convert F to a KeyEvent.
2. Use the obsolete setMnemonic method that accepts a char.
3. Use an int in the prop file.
4. Not bother with menu short cuts.
I guess 'obsolete' is not as bad a 'deprecated', but I don't really like any of the options. I may just go with option 4, since I've got bigger issues to solve elsewhere in the assignment.
Cheers
 
Rob Pearson
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrew,
Thanks for the reply, I missed your post before sending my last reply.
It is more of a "real world" problem. I just wondered if there were other ways that I'd missed.
I'm not really comfortable using an obsolete method on the assignment, so I think I'll just forget about the menu short cuts. Its not as if there's going to be much in the menus anyway!
Cheers
 
Damian Ryan
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used the "obsolete" method to mark my mnemonics and it didn't do me any harm (155/155)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic