I'm trying to implement a button to make both my JFrame and JPanel bigger (by the same amount), but it doesn't quite seem to work.
myPanel.setPreferredSize(new Dimension(50, 50));
button1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
getContentPane().remove(myPanel);
myPanel.invalidate();
myPanel.setMinimumSize(new Dimension(myPanelWidth, myPanelHeight+100));
myPanel.setBounds(new Rectangle(myPanel.getBounds().getX(), myPanel.getBounds.getY(), myPanel.getBounds().getWidth(), myPanel.getBounds().getHeight+100));
getContentPane().setBounds(new Rectangle(myFrameX, myFrameY, myFrameWidth, myFrameHeight+100));
getContentPane().add(myPanel, BorderLayout.SOUTH);
System.out.println(myPanel.getBounds().getHeight());
myPanel.validate();
myPanel.repaint();
The problem is that my frame resizes properly - it becomes 100 units bigger, but the panel doesn't. I'm not sure I'm validating and repainting properly. What am I doing wrong?
Edit: Fixed! I needed a setPreferredSize()
update inside of my ActionListener
.