| Author |
Fixed Cellsize in GridBagLayout
|
M Bryan
Ranch Hand
Joined: Jun 15, 2011
Posts: 57
|
|
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
Joined: Oct 27, 2005
Posts: 19216
|
|
|
Start with setting the weightx to 0.0. With 1.0 it grows when the container is resized.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Darryl Burke
Bartender
Joined: May 03, 2008
Posts: 4164
|
|
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?
|
luck, db
There are no new questions, but there may be new answers.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
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.
|
 |
 |
|
|
subject: Fixed Cellsize in GridBagLayout
|
|
|