菜单栏右侧的Swing菜单项 [英] Swing menu item on right of Menu Bar
问题描述
我有一个swing应用程序,并且我想在JFrame的菜单上添加一个Help MenuItem,但将其右对齐.
有任何想法吗 ?
I have a swing application and on the JFrame's menu I want to add a Help MenuItem, but have it Right justified.
Any ideas ?
Swing JMenuBar具有BoxLayout,我已经尝试过:
A Swing JMenuBar has a BoxLayout and I have tried:
menuItem = new JMenuItem("Help");
menuItem.setAlignmentX(Box.RIGHT_ALIGNMENT);
menuBar.add(menuItem);
菜单仅停留在左侧. 我也尝试过:
The menu just stays on the left. I have also tried:
menuBar.add(Box.createHorizontalGlue());
按照Swing教程...,但这只是增加了一个空格.
as per the Swing Tutorial... but that just adds a space.
我正在使用Windows7.JDK 1.6.26
I am using Windows 7. JDK 1.6.26
如果执行此操作,则按照Java教程进行操作:
It works as per the Java Tutorial if I do:
menuBar.add(Box.createHorizontalGlue());
helpMenu = new JMenu("Help");
menuBar.add(helpMenu);
menuItem = new JMenuItem("Help");
helpMenu.add(menuItem);
但这不是我想要的.我只希望能够将帮助MenuItem添加到JMenuBar.现在,这将是我的后备.
But that is not what I am looking for. I just want to be able to add the help MenuItem to the JMenuBar. For now that will need to be my fallback.
推荐答案
尝试Component.setComponentOrientation()
方法.
menuItem.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
这篇关于菜单栏右侧的Swing菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!