为什么JInternalFrame的setSize不起作用
我制作了一个JFrame,并在JFrame中添加了一个JDesktopPane,然后在JDesktopPane中添加了一个JInternalFrame,JInternalFrame的初始大小与JDesktopPane相同。当 JFrame 最大化时,JDesktopPane 也会最大化,但 JInternalFrame 不会最大化。而且我希望JFrame最大化时JInternalFrame也最大化,所以我为JFrame添加了一个WindowStateListener,当JFrame最大化时,我会调用JInternalFrame的setSize方法使JInternalFrame的大小与JDesktopPane相同,代码如下:
addWindowStateListener(new java.awt.event.WindowStateListener() {
public void windowStateChanged(java.awt.event.WindowEvent evt) {
jInternalFrame.setSize(jDesktopPane1.getWidth(),
jDesktopPane1.getHeight());
}
});
但是不起作用。但是当我单击最大化 JFrame,然后单击最小化 JFrame,然后单击任务栏让 JFrame 可见时,它确实有效。
为什么会出现这样的情况呢?
I make a JFrame, and add a JDesktopPane into the JFrame, and then add a JInternalFrame into the JDesktopPane, the JInternalFrame' initial size is the same as JDesktopPane. When the JFrame is maxmized, the JDesktopPane will also be maximized, but the JInternalFrame is not maximized. And I want that the JInternalFrame is maximized when the JFrame is maximized, so I add a WindowStateListener for the JFrame, when the JFrame is maximized,I will call JInternalFrame' setSize method to make the JInternalFrame' size is the same as the JDesktopPane, the code is as follows:
addWindowStateListener(new java.awt.event.WindowStateListener() {
public void windowStateChanged(java.awt.event.WindowEvent evt) {
jInternalFrame.setSize(jDesktopPane1.getWidth(),
jDesktopPane1.getHeight());
}
});
but it does not work. but when I click to maximize the JFrame, and then I click to minimize the JFrame, and then click taskbar to let the JFrame visible, and it does work.
Why it happen like this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否对包含 JInternalFrame(JDesktopPane)的容器调用 repaint?如果没有,你应该这样做。
Do you call repaint on the container that holds the JInternalFrame, the JDesktopPane? If not, you should.
我将在
JDesktopPane
上使用ComponentListener
并侦听componentResized
事件。然后,每当桌面窗格大小发生变化时,无论是通过最大化/恢复还是通过调整框架大小,您都会收到通知。I would use a
ComponentListener
on theJDesktopPane
and listen for thecomponentResized
event. Then whenever the desktop panes size changes, either by maximize/restore or by resizing the frame you will be notified.听起来您只是希望 JInternalFrame 遵循 JFrame 的状态。为什么不将 JInternalFrame 也设置为最大化呢?
It sounds like you just want the JInternalFrame to follow the state of the JFrame. Why don't you just set the JInternalFrame to be maximized as well?