• Post Reply Bookmark Topic Watch Topic
  • New Topic

JMenuItem text alignment to CENTER

 
Renjith mohanan
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I need to set the text of the JMenuItem to be center.
I have a JPopupMenu and added many JMenuItem(String) object to it.

This is my code and I tried several ways, but the text of the MenuItem is going to center..



Please help me to align the text of JMenuItem to be center.

Any Help will be appreciable

Thanks in Advance

Renjith M



 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try adding them to a JPanel first - default FlowLayout should center them,
but you may need to tweak the panel's border etc

//popMenu.add(item);
JPanel p = new JPanel();
p.add(item);
popMenu.add(p);


 
Renjith mohanan
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Michael,

Thanks for your help.

But I did not understand the line

but you may need to tweak the panel's border etc

Did you meant, whether I need to set the panel border to empty border.

Thanks
Renjith M
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> But I did not understand the line
> but you may need to tweak the panel's border etc

just that the items may be spaced further apart than normal,
if that is OK, nothing needs to be done
 
Rob Camick
Ranch Hand
Posts: 2700
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might be able to use this Popup Menu Alignment suggestion.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!