如何在单击事件中增加/减少窗口大小? [英] how can i increase/decrease size of window on click event?

查看:21
本文介绍了如何在单击事件中增加/减少窗口大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个简单的 Swing 应用程序,其中有一个带有三个按钮的主窗口.当我单击第一个按钮时,它会打开 (200,200) 维的新窗口.当我点击第二个按钮时,新打开的窗口的高度应该增加,当我点击第三个按钮时,高度应该减少.你能帮我写代码吗....

I am developing a simple swing app in which I have a main window with three buttons. When I click on the first button it opens new window of (200,200) dimension. When I click on the second button, the newly opened window's height should get increased and when I click on third button height should get decreased. Can you help me with code....

提前致谢.

推荐答案

您可以在要调整大小的新打开窗口上执行以下操作:

you could do the following on the newly opened windows which you want to resize:

JFrame fr=getNewlyOpenendWindowReference(); // get a reference to the JFrame
fr.setSize(fr.getSize().getWidth() + 10,fr.getSize().getHeight() + 10);
fr.repaint();

这应该会在每次调用时将 JFrame 的长度和宽度增加 10 个像素.

this should increase the size of the JFrame length and widthwise by 10 pixels per call.

这篇关于如何在单击事件中增加/减少窗口大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆