如何我可以改变的JMenuItem对齐右对齐 [英] How I can change JMenuItem alignment to right align
本文介绍了如何我可以改变的JMenuItem对齐右对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经用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.
这篇关于如何我可以改变的JMenuItem对齐右对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文