Java: Changing preferredSize()

250 Views Asked by At

How do you change the preferredSize() of a java program, after setVisible()? For example, you have a program that is 100x200, but when you click a button it changes to something else like 300x100.

Thanks in advance for any help.

1

There are 1 best solutions below

0
iperezmel78 On

Assuming you called setVisible method like this

new MyWindow().setVisible(true);

And your button's click event name is myButtonActionPerformed, then this code will work:

private void myButtonActionPerformed(java.awt.event.ActionEvent e) {
     setSize(new java.awt.Dimension(300, 100));
}