pane.setBounds(20, 20, WIDTH - 40, 300 - 40);
pane.setPreferredSize(new Dimension(WIDTH - 40, 300 - 40));
These two lines of code do not make sense (although they are not the cause of your problem)
The first line is used when you use the "zero layout".
The second is used when you use layout managers.
They should not be used together.
The second is preferable since you should use layout managers.
source
share