aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes GridBagLayout resize issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "GridBagLayout resize issue" Watch "GridBagLayout resize issue" New topic
Author

GridBagLayout resize issue

David Miranda
Ranch Hand

Joined: Mar 14, 2005
Posts: 34
Hello,

Im trying to left-orient a JLabel and JList in a GridBagLayout panel thats in a split pane.

I'm using a GridBagLayout because I'm trying to left orient everything in the panel...I tried to use a BoxLayout but everything was center-oriented, the only way I found to get the Label to become left-oriented in the pane was to increase the size of the label to size of the surrounding pane (I dont want to hard code the size of the label )

I want the the GridBagLayout panel to resize correctly when the split pane is pulled up and down....but when I move the drag the split pane up towards the list, the JList gets crushed...not shrunk like expect...crushed and center-oriented in the panel

Please tell me what I'm doing wrong!

Also, if anybody can tell me how to left-orient components in the surrounding pane without using a GridBagLayout or hard-coding the component size, that'd be great.

Thanks,

David

Here's my code:



[ June 30, 2007: Message edited by: David Miranda ]
[ July 01, 2007: Message edited by: David Miranda ]
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
David Miranda
Ranch Hand

Joined: Mar 14, 2005
Posts: 34
Thanks Mike

Does anyone know why the GridBagLayout code crushed the contents when the panel resize made it smaller?

Thanks
[ July 01, 2007: Message edited by: David Miranda ]
David Miranda
Ranch Hand

Joined: Mar 14, 2005
Posts: 34
EUREKA!

Well, the fix was remarkably easy.

Turns out that I needed to set the constraints fill to GridBagConstraints.BOTH for the component that I want to fill the remainder of both the horizontal and vertical space.

Here's the code for those who may come after with this problem (I've seen at least a half-dozen before me using search)


[ July 01, 2007: Message edited by: David Miranda ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GridBagLayout resize issue