• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

GridBagLayout Problem

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out MigLayout if you are interested.
http://www.miglayout.com/
 
Your buns are mine! But you can have this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic