• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to set JMenuItem's height ?

 
Bartek Myszkowski
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11064
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Bartek Myszkowski
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You for fast reply Maneesh it works
 
Maneesh Godbole
Saloon Keeper
Posts: 11064
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic