File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes menu behaviour when resizing windows in Swing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "menu behaviour when resizing windows in Swing" Watch "menu behaviour when resizing windows in Swing" New topic
Author

menu behaviour when resizing windows in Swing

Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Hi,
Hoping to get some suggestions or pointers.
How do I make the menubar behave like MS windows fashion, when the window is resized. Perhaps one of the following behaviour.
1. A scroll arrow thing appears, if all the menus cannot be displayed - IE
2. The menu's wrap into the next row - Visual InterDev, Notepad
3. or even, only the left-most menus are displayed, if there is not enough room.
I have looked at Javadocs and java sources, the only way seems to be to pass the menubar your own layout manager object(GridbagLayout is probabely most appropriate), but that is gonna be a bit of a hassle, i want to leave that as the last choice.
Would Eclipse's SWT library be better at this kind of thing?
thanks
Sandeep


The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny Gill Tweets
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
hi,
this code will place the menus starting on the left side. each item will keep its size even when the window is resized. the right most menus will disappear if the window gets to small.

how to make the JMenuBar have more lines or diplay a scrollpane want work without subclassing it, I think. at least not the scrollpane solution as JFrame wants a JMenuBar as argument.
chantal
[ October 17, 2002: Message edited by: Chantal Ackermann ]
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Thanks Chantal,
Unfortunately, that did not solve my problem. If i set the layout to FlowLayout, it messes up the appearance of the menubar(The bottom border does not appear properly), and leaves too much space between menus(even when i specify the horizontal gap to be 0).
I might have to look at subclassing one of the classes in javax.swing.plaf.basic that provide the UI to a menubar.
sunny
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Found it on sun's bug parade
http://developer.java.sun.com/developer/bugParade/bugs/4099794.html
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: menu behaviour when resizing windows in Swing