views:

56

answers:

2

Hi Coders,

I am in the process of developing a simple JFrame based GUI to which I've added a JMenuBar and which in turn has the usual JMenuItems added to it - "File:", "Edit:", etc.

I would like to be able to add another JMenuItem - "About:" - to the far right-hand side of the JMenuBar. Is this possible without too much hackery - I would like a lean, simple way to do this if it's possible?

This is what I'm trying to achieve:

----------------------------------------------------------------------------------------
File: Edit: Tools:                                                                About:      
----------------------------------------------------------------------------------------

Thanks for helping out :-)

Edit \ Update - 12-8-2010: Edited the title of my question to read JMenu instead of JMenuItem.

Compiled a simple app to test the code given in the accepted answer below and it works perfectly !!!

+5  A: 

See http://download.oracle.com/javase/tutorial/uiswing/components/menu.html#custom

//...create and add some menus...
menuBar.add(Box.createHorizontalGlue());
//...create the rightmost menu...
menuBar.add(rightMenu);
jmo
Thanks for both the link and the code, jmo. Much appreciated and accepted as the answer.
The Thing
A: 

An alternative to using glue (which is the best solution in this case), would be to use an empty border. This wouldn't be dynamic like glue though as it would have a fixed width.

Split Personality