Swing 中的窗口最小化
我创建了一个框架并将其扩展状态设置为 JFrame.MAXIMIZED_BOTH
。该窗口在启动时显示为最大化,但在我按下“恢复”按钮后,它的大小调整为零大小的窗口,只有上部,其中包含最小化、最大化和关闭按钮。之后我可以手动调整窗口大小,并显示内容。
我希望我的窗口在启动时最大化,但不想在单击恢复按钮后丢失它。
这是代码:
public class MyFrame extends JFrame {
public MyFrame() {
//...
setExtendedState(getExtendedState() | JFrame.MAXIMIZED_BOTH);
setVisible(true);
}
}
I've created a frame and set it extended state to JFrame.MAXIMIZED_BOTH
. The window appears maximazed at startup, but after I pressed "Restore" button, it resizes to zero-sized window with only upper part, which contains minimize, maximize and close buttons. After that I can resize window manually, and the content is shown.
I want my window to be maximized at startup, but don't want to lose it after restore button click.
Here is the code:
public class MyFrame extends JFrame {
public MyFrame() {
//...
setExtendedState(getExtendedState() | JFrame.MAXIMIZED_BOTH);
setVisible(true);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该在
setVisible(true)
之前调用pack()
以确保正确计算首选大小。我认为恢复应该可以正常进行。You should call
pack()
beforesetVisible(true)
to make sure the preferred size is properly calculated. I think then restore should work properly.也许你应该尝试这个:
Probably you should try this: