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 ?
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());
as per the Swing Tutorial... but that just adds a space.
I am using Windows 7. JDK 1.6.26
EDIT: 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);
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.
Try Component.setComponentOrientation()
method.
menuItem.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);