开发者

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)sourc开发者_开发知识库e.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?


Try this:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜