How I can change JMenuItem alignment to right align

六月ゝ 毕业季﹏ 提交于 2019-12-06 02:08:00

问题


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


回答1:


    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.



来源:https://stackoverflow.com/questions/13140964/how-i-can-change-jmenuitem-alignment-to-right-align

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!