JFrame.setPreferredSize() is not working consistently

Hello, so I have this JFrame, and on one computer it worked fine, but when I transferred my project over to another computer it started to have issues, sometimes it would work like a charm without a hitch, and others setPreferredSize() doesn’t work, so it creates a JFrame that is the minimum size and them crashes because of things that depend on window size.

Thanks,
h3ckboy

Different OSs, or just different machines?

“sometimes it works” is a key phrase for threading issues, maybe improper dealing with threads.

both are windows 7.

Yes, I am using multiple threads, but all thread related code is after this line.

The contents (component/jpanel/wat), are they changing in run?

What do you mean changing? I am adding components to it if thats what you mean.

What works for me is calling setSize and setPreferredSize both with same value.

I always only call setSize() or pack().

What about adding a JPanel to the JFrame, calling setPreferredSize() on the panel, and pack() on the frame. Then add your components to the panel. It’s normally the panel you want a particular size anyway, not the window.

Waterwolf’s method worked like a charm,

thank you all for your help :slight_smile: