• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Fixed Cellsize in GridBagLayout

 
M Bryan
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • 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!
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start with setting the weightx to 0.0. With 1.0 it grows when the container is resized.
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic