6

I have written a program in java with netBeans editor.

my form have a jmenuBar with some jmenu in right alignment.

for example jmenu1 have some jmenuItem, i want right align all jmenuitem's text.

when i change Horizontal alignment of them to right, text not shown when i run it.

menuItem1.setHorizontalAlignment(SwingConstants.RIGHT);

How i can do it?

http://upcity.ir/images/18431917276667197781.jpg

  • is 'Sub Menu' not right aligned now? You should experiment with different menu items of different lengths. At the moment the menu is as wide as the text – RNJ Oct 30 '12 at 14:27
  • @MyNameIsTooCommon have to calculating that (read OPs name) there are used ComponetOrientaions.RTL too, maybe not, nobody knows, I added SSCCE with Image, because could be an interesting question, doeasn't matter of LTR or RTL ... – mKorbel Oct 30 '12 at 14:30
  • Please have a look at [this](http://stackoverflow.com/a/10472124/1057230) and [this](http://stackoverflow.com/a/10503190/1057230) answer of mine. Might be, they be of some help :-) – nIcE cOw Oct 30 '12 at 14:58
  • @Gagandeep Bali do you think works with RTL Orientations – mKorbel Oct 30 '12 at 15:52
  • Yeah I guess dude, though, hadn't used JMenu that much. + up voted the question from my side, when I wrote my first comment, for more attention. – nIcE cOw Oct 30 '12 at 16:18

1 Answers1

2
    JMenuItem item1 = new JMenuItem("Item 1");
    JMenuItem item2 = new JMenuItem("Item ________ 2");
    JMenuItem item3 = new JMenuItem("Item 3");

    item1.setHorizontalAlignment(SwingConstants.RIGHT);
    item3.setHorizontalAlignment(SwingConstants.CENTER);

It works for me. The problem might be in length of items - they are the same thus right alignment is not visible.

KrHubert
  • 1,030
  • 7
  • 17