aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes GridBagLayout Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "GridBagLayout Problem" Watch "GridBagLayout Problem" New topic
Author

GridBagLayout Problem

Axel Leucht
Greenhorn

Joined: Jan 19, 2009
Posts: 21
I do have a problem with the GUI-Layout.

Problem is: Initially everything looks ok. But whenever I resize the panel to a very small size, the JTextfields "jump" to their minimum size. which looks very bad.

Here is some code to demonstrate what I mean and I would appreciate any help on this issue.



Regards

SCJP, SCJD
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Perhaps setting weights of your components will help. Myself, I would avoid GridBagLayout unless forced. Instead I nest simpler layouts. For instance:
Mikko Kohtamäki
Ranch Hand

Joined: Dec 13, 2008
Posts: 112
Try adding your panel to JScrollPane, that way components wont slide to left when resizing and you may want to set preferred size for labels.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
this seems to work OK, but GridBagLayout has a habit of 'fixing one thing, breaks another 2'
so just needs a lot of testing to see how it stands up.

1) get rid of the column setting for each textfield
//javaCersion.setColumns(10);

2) include an ipadx of 100 (2nd last argument), but only for the 4 textFields
//new Insets(5, 5, 0, 5), 0, 0));
new Insets(5, 5, 0, 5), 100, 0));

this should get you close to the size you want for the textfields, if not, modify the 100
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10523
    
    9

Check out MigLayout if you are interested.
http://www.miglayout.com/

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GridBagLayout Problem