Reputation: 14418
I want to be able to resize the JFrame when I click a button, so here's the code:
public void mouseClicked(MouseEvent arg0) {
try {
JPanel source = (JPanel)arg0.getSource();
JPanel parent = (JPanel)source.getParent().getParent().getParent().getParent();
parent.getParent().setSize(new Dimension(1400,800));
((JLayeredPane) parent.getParent()).revalidate();
}
but the code above is not resizing my JFrame, why is this?
Upvotes: 0
Views: 260
Reputation: 24709
Try this:
SwingUtilities.windowForComponent(source); // where source is your button
window.setSize(new Dimension(1400,800));
Upvotes: 1