The Artima Developer Community
Sponsored Link

Java Answers Forum
JMenuItem.setText question.

2 replies on 1 page. Most recent reply: May 20, 2002 11:39 PM by Ben Trafford

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Ben Trafford

Posts: 7
Nickname: btrafford
Registered: May, 2002

JMenuItem.setText question. Posted: May 20, 2002 6:50 PM
Reply to this message Reply
Advertisement
Okay...

In Windows, when you hit File menus, you get a drop-down list. The drop-down list contains things like New, some space, and then Ctrl+N.

I want to do the same thing in a Java GUI, where all the nice little Ctrl+FOOs line up.

One would think that this would do the trick:

JMenuItem.setText("New\t\tCtrl+N");


It doesn't. The escape characters are utterly ignored. Spaces won't work, because I'm not using a fixed width font.

Anybody have any idea how to nicely line up all my Ctrl+FOOs?

Any advice or help would be appreciated.


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: JMenuItem.setText question. Posted: May 20, 2002 10:18 PM
Reply to this message Reply
If I remember correctly, you use the item's (JMenu or JMenuItem) setMnemonic() method, to have the underlined letter that you can use in combination with opening the menu via shorcuts (like "Alt-F" then "X" to exit, for example). To get the application-wide shortcut, or accelerator (like Ctrl-S to save, for example), you use the setAccelerator().

Ben Trafford

Posts: 7
Nickname: btrafford
Registered: May, 2002

Re: JMenuItem.setText question. Posted: May 20, 2002 11:39 PM
Reply to this message Reply
> If I remember correctly, you use the item's (JMenu or
> JMenuItem) setMnemonic() method, to have the
> underlined letter that you can use in combination
> with opening the menu via shorcuts (like "Alt-F" then
> "X" to exit, for example). To get the
> application-wide shortcut, or accelerator
> (like Ctrl-S to save, for example), you use the
> setAccelerator().


With a bit of research into the API docs, I figured it out, from your help. Many thanks!

Flat View: This topic has 2 replies on 1 page
Topic: need help pls Previous Topic   Next Topic Topic: Why doesn't this work?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use