aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to set JMenuItem's height ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to set JMenuItem Watch "How to set JMenuItem New topic
Author

How to set JMenuItem's height ?

Bartek Myszkowski
Ranch Hand

Joined: Feb 03, 2009
Posts: 44
Hello,

I'd like to set JMenuItem's height to specified size (width should be auto set to see full text). Method setMinimumSize(X, Y) is ignored (anyone know why?). Method setPreferredSize(X, Y) sets size exactly to X, Y even if it cuts the text of JMenuItem. I've been also tring to work out something with menu.getPopupMenu() and it's layout but without results.. What I'd like to get, is JMenuItem with height of Y and width set to largest JMenu's item (to see whole text; check image at bottom of this post).

I believe this is very easy to do.. but have no ideas how.. I appreciate any suggestions.

Sample code to see the problem:
this is what I've got (text is cut):




this is what I'd like to get (created with graphic editor!):

Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

You are explicitly setting the width to 100. Let the system handle the width. (a call to super should give you the correct width which will display the full text contents)

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Bartek Myszkowski
Ranch Hand

Joined: Feb 03, 2009
Posts: 44
Thank You for fast reply Maneesh it works
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

You are welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to set JMenuItem's height ?
 
Similar Threads
mnemonics are not getting focus for the menubar
adding an InternalFrameListener to a JMenu Item
Gridbag Layout
Menu Bar
JTextArea append() not working?