我已经用Java编写的程序与的NetBeans
编辑。
我的表格有一个的JMenuBar
一些 JMenu的
右对齐。
例如 jmenu1
有一些的JMenuitem
,我想右对齐所有的JMenuItem
的文本。
menuItem1.setHorizontalAlignment(SwingConstants.RIGHT);
我该怎么办呢?
解决方案
JMenuItem的ITEM1 =新的JMenuItem(项目1);
JMenuItem的项目2 =新的JMenuItem(项目________ 2);
JMenuItem的项目3 =新的JMenuItem(项目3);
item1.setHorizontalAlignment(SwingConstants.RIGHT);
item3.setHorizontalAlignment(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.