Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Aligning JMenuItems  RSS feed

 
Puneet Gupta
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a Menu that contains quite a few JMenuItems.
The JMenuItems can be with text only and can contain text as well as icons. I want to arrage the JMenuItems so that all text is vertically aligned ie
If the JMenuItem contains an image it should be visible to extreme left and the text of the JMenuItem should be aligned with the text of the JMenuItem without icon.
Any Help in this topic is heartly solicited.
Cheers
Puneet
 
keerthi matta
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I dont know whether this will solve ur requirement
We can align the Text of the JMenuItem with the help of
menuItem.setHorizontalTextPosition(int) method,
so when we set it as
menuItem.setHorizontalTextPosition(SwingConstants.LEFT);
The text will always be visible to the Left of the icon of the menuItem.

keerthi
 
Puneet Gupta
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Keerthi,
But this is not what I desire. By default the text appears to the right of an icon and the method setHorizontalTextPosition allows user to set his/her preference ie. to override the default.
What I exactly mean is that when you add to JMenuItem viz:
1. with text only
2. with text and icon
the text of the two JMenuItem should be aligned
By default it Looks like:
Save
(Image) Save As
Desired Behaviour:
Save
(image) Save As ( text here are aligned)
Puneet
 
keerthi matta
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Puneet,
I cant get to ur problem
The Default behaviour and the Desired behaviour are same ,
can u please explain the question in detail
keerthi
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The easiest thing to do would be to make an "empty" icon that takes up as much space as your others... This could either be an ImageIcon of a completely transparent image, or you could just make an Icon that paints a square the same color as the component's background...

-Nate
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!