aherlambang
aherlambang

Reputation: 14418

setting the size of a JFrame

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

Answers (1)

Joshua McKinnon
Joshua McKinnon

Reputation: 24709

Try this:

SwingUtilities.windowForComponent(source); // where source is your button
window.setSize(new Dimension(1400,800));

Upvotes: 1

Related Questions