简体   繁体   English

菜单栏右侧的Swing菜单项

[英]Swing menu item on right of Menu Bar

I have a swing application and on the JFrame's menu I want to add a Help MenuItem, but have it Right justified. 我有一个swing应用程序,在JFrame的菜单上,我想添加一个Help MenuItem,但是让它正确对齐。
Any ideas ? 有任何想法吗 ?

A Swing JMenuBar has a BoxLayout and I have tried: 一个Swing JMenuBar有一个BoxLayout,我尝试过:

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());  

as per the Swing Tutorial... but that just adds a space. 根据Swing教程......但这只是增加了一个空间。

I am using Windows 7. JDK 1.6.26 我使用的是Windows 7. JDK 1.6.26

EDIT: It works as per the Java Tutorial if I do: 编辑:如果我这样做,它按照Java教程工作:

    menuBar.add(Box.createHorizontalGlue());

    helpMenu = new JMenu("Help");
    menuBar.add(helpMenu);
    menuItem = new JMenuItem("Help");
    helpMenu.add(menuItem);  

But that is not what I am looking for. 但这不是我想要的。 I just want to be able to add the help MenuItem to the JMenuBar. 我只想将帮助MenuItem添加到JMenuBar。 For now that will need to be my fallback. 现在,这需要成为我的后备。

尝试使用Component.setComponentOrientation()方法。

menuItem.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

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

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