• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Fixed Cellsize in GridBagLayout

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

with the GridBagLayout i am creating a table and in the cells i am showing numbers. The numbers change, depending on what the user does.
The problem is now: When the length of the numbers change, so does the size of the corresponding cell. And when the cell size changes, so does the position of all the other cells and the whole table is moving, which doesn't look very nice. How can i tell the GridBagLayout to keep one cell size, no matter how the cell contents change?

This is my GridBagConstraint:



Thanks in advance!
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Start with setting the weightx to 0.0. With 1.0 it grows when the container is resized.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Um, weightx (and weighty) specify how extra space is to be allotted, so this won't make a difference in a case where the preferredSize of contained components changes.

Bryan, your code snippet lacks one very important detail: what components are used to show the numbers. To get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem.

Unless there's more to your question than is apparent from what you've posted, why aren't you using a GridLayout?
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the changing preferred size is the problem, that can be prevented by creating the text fields with a specified number of columns. Those columns will be used to determine the fixed size.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic