我希望能够在单击按钮时调整JFrame的大小,所以这是代码:
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();
}
但上面的代码没有调整我的JFrame大小,为什么会这样?
答案 0 :(得分:1)
试试这个:
SwingUtilities.windowForComponent(source); // where source is your button
window.setSize(new Dimension(1400,800));