The Thing
The Thing

Reputation: 635

Java - Is It Possible To Add A JMenu Over On The Far Right-Hand Side Of A JMenuBar?

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 !!!

Upvotes: 2

Views: 1623

Answers (2)

Split Personality
Split Personality

Reputation: 33

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.

Upvotes: 1

jmo
jmo

Reputation: 452

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

Upvotes: 7

Related Questions