Alright, I have been cruising through the net looking for some help with this one, but nothing I try seems to work. I want to have all of the menu texts centered on their menu buttons. When I use setHorizontalTextPosition(JMenu.CENTER) there is no change. In fact, regardless of the constant I use, the menu text remains left justified.
Any ideas?
*UPDATE 1
Still no luck. After re-reading the JMenu API, I realized that setHorizontalTextPosition(int) and setVerticalTextPosition(int) only set the text in relation to an icon and setHorizontalAlignment(int) and setVerticalAlignment(int) set the alignment of both text and icon in the JMenu.
The text positioning methods seem to work as advertised when used with an icon.
The vertical alignment method seems to work on text or icon or both.
However, the horizontal alignment method doesn't seem to work at all. Even just using it alone on text or icon or both, nothing seems to change. I have increased the menu size to 150x50 and, no matter the combination, I can't get the text or icon or either to center horizontally.


Try
setHorizontalTextPosition(SwingConstants.CENTER);followed byinvalidate();alternatively use margins:
I made a short SSCCE to see if I could re-enact the problem but mine seems perfectly aligned from the start no need for any of the above:
Link to screenshot: http://img713.imageshack.us/img713/1489/67449235.jpg
Reference: