1

我制作了一个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可见,它确实有效。

为什么会这样?

4

3 回答 3

1

您是否在包含 JInternalFrame、JDesktopPane 的容器上调用 repaint?如果没有,你应该。

于 2011-11-15T11:53:08.133 回答
1

我会使用 aComponentListenerJDesktopPane监听componentResized事件。然后,每当桌面窗格大小发生变化时,通过最大化/恢复或调整框架大小,您都会收到通知。

于 2011-11-15T16:08:00.520 回答
1

听起来您只希望 JInternalFrame 遵循 JFrame 的状态。为什么不将 JInternalFrame 也设置为最大化?

jInternalFrame.setMaximum( true );
于 2011-11-15T16:13:53.967 回答