• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GridBagLayout Problem

 
Axel Leucht
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11096
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out MigLayout if you are interested.
http://www.miglayout.com/
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic