Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NetBeans (Java Swing): Set window size

This is driving me crazy. When I set an appropriate size for my window in design-mode it just ignores this size and uses something else when I compile and run. Even tough I set the minimumSize and preferredSize it just ignores this... Why? How can I set my own size?

like image 320
Johan Avatar asked Dec 19 '09 14:12

Johan


2 Answers

Even if you've set the size with minimumSize and preferredSize, you might have forgotten to call Window.pack() in which Swing will resize the components (and all of it's subcomponents) according to the sizes set.

You call it in your window (or whatever is building your window) after all the preferred sizes are set.

Alternatively you can use the Component.setSize() method but it comes with some caveats.

like image 55
Spoike Avatar answered Sep 20 '22 16:09

Spoike


Have you checked if you really set the size of the JFrame or of a contained JPanel?

Have you tried setSize?

like image 43
Peter Lang Avatar answered Sep 16 '22 16:09

Peter Lang