문제

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

도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top