• Post Reply Bookmark Topic Watch Topic
  • New Topic

JMenuItem text problem  RSS feed

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there,

I have a JMenuBar, with several JMenu's containing JMenuItem's.

As an example...

Save________S
Close________C
Exit_________F1

I will have spaces though, not underscores.
I'm struggling to get the letters to line up with the Font I'm using.
Not sure which one it is.

I can solve this using Monospaced Font, but it looks bad, and I would rather avoid it.
Is there another way I can get all the words lined up to the left, and the keys representing them lined up to the right?

Thanks for any help

[ August 28, 2007: Message edited by: colin shuker ]
[ August 28, 2007: Message edited by: colin shuker ]
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arent you using Mnemonics and Accelerators? In that case you dont need to explicitly do the alignment.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow...

Didn't know you could do that, thanks

I looked briefly at the methods in JMenuItem, I must have overlooked this setAccelerator method.

The great thing is... I don't need to use KeyListener's or KeyBinding's,
the key presses will just automatically link the to JMenuItems action.
This is a much better way of doing it, I'm glad I asked now.

Thanks
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!