0

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.

Ryan
  • 727
  • 2
  • 14
  • 31

1 Answers1

0

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));
}
iperezmel78
  • 415
  • 5
  • 20