I’ve found that my container is actually changing it’s size a short while after being constructed
When it’s constructed, I set my components to be at the place I want (like 30px away from the right edge) but later after a short while, I find that it turns from 1008×730 to 1018×740…
(My JFrame is 1024×768)
Does anyone know why this happens and how I can stop this auto-resizing thing?
Thank you.
I just did a –
while (true) {
System.out.println(c.getSize());
}
And the size changed after a few iterations.
~Edited
It sounds like you’re doing something that changes a component’s size and revalidates after calling
pack()on theJFrame. Also, rather than callingsetSize(), it’s often better to set a component’s preferred size and let theLayoutManagerarrange things.Addendum: It’s generally better to invoke
pack()on a top-level container in order to get the initial sizes correct. Also, the content pane of aJFramedefaults toBorderLayout, which may not be what you want.