如何我可以改变的JMenuItem对齐右对齐右对齐、JMenuItem

2023-09-12 21:26:28 作者:咫尺天涯间

我已经用Java编写的程序与的NetBeans 编辑。

我的表格有一个的JMenuBar 一些 JMenu的右对齐。

例如 jmenu1 有一些的JMenuitem ,我想右对齐所有的JMenuItem 的文本。

当我改变他们的水平对齐方式来权当我运行它,文字未显示

  menuItem1.setHorizo​​ntalAlignment(SwingConstants.RIGHT);
 

我该怎么办呢?

解决方案

  JMenuItem的ITEM1 =新的JMenuItem(项目1);
    JMenuItem的项目2 =新的JMenuItem(项目________ 2);
    JMenuItem的项目3 =新的JMenuItem(项目3);

    item1.setHorizo​​ntalAlignment(SwingConstants.RIGHT);
    item3.setHorizo​​ntalAlignment(SwingConstants.CENTER);
 
编辑器如何操作文字能增加文字呼吸感

这对我的作品。这个问题可能是项目的长度 - 他们是相同的。因此右对齐是不可见的。

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?

解决方案

    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.