简体   繁体   English

我如何将JMenuItem对齐方式更改为右对齐

[英]How I can change JMenuItem alignment to right align

I have written a program in java with netBeans editor. 我已经用netBeans编辑netBeans Java编写了一个程序。

my form have a jmenuBar with some jmenu in right alignment. 我的表单有一个jmenuBar ,其中有一些jmenu对齐。

for example jmenu1 have some jmenuItem , i want right align all jmenuitem 's text. 例如jmenu1有一些jmenuItem ,我想右对齐所有jmenuitem的文本。

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 http://upcity.ir/images/18431917276667197781.jpg

    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. 问题可能出在项目的长度上-它们相同,因此看不到正确的对齐方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM