Java 为什么JInternalFrame';这不管用
我制作了一个JFrame,在JFrame中添加一个JDesktopPane,然后在JDesktopPane中添加一个JInternalFrame,JInternalFrame的初始大小与JDesktopPane相同。当JFrame最大化时,JDesktopPane也将最大化,但JInternalFrame不会最大化。我希望JFrame最大化时JInternalFrame最大化,所以我为JFrame添加了一个WindowsStateListener,当JFrame最大化时,我会调用JInternalFrame的setSize方法,使JInternalFrame的大小与JDesktopPane相同,代码如下:Java 为什么JInternalFrame';这不管用,java,swing,jinternalframe,jdesktoppane,Java,Swing,Jinternalframe,Jdesktoppane,我制作了一个JFrame,在JFrame中添加一个JDesktopPane,然后在JDesktopPane中添加一个JInternalFrame,JInternalFrame的初始大小与JDesktopPane相同。当JFrame最大化时,JDesktopPane也将最大化,但JInternalFrame不会最大化。我希望JFrame最大化时JInternalFrame最大化,所以我为JFrame添加了一个WindowsStateListener,当JFrame最大化时,我会调用JInterna
addWindowStateListener(new java.awt.event.WindowStateListener() {
public void windowStateChanged(java.awt.event.WindowEvent evt) {
jInternalFrame.setSize(jDesktopPane1.getWidth(),
jDesktopPane1.getHeight());
}
});
但它不起作用。但是当我单击以最大化JFrame,然后单击以最小化JFrame,然后单击任务栏以使JFrame可见时,它确实工作了
为什么会发生这种情况?您是否会在保存JInternalFrame(JDesktopPane)的容器上调用重新绘制?如果没有,您应该这样做。我会在
JDesktopPane
上使用ComponentListener
,并侦听componentresistized
事件。然后,每当桌面窗格大小发生变化时,无论是通过最大化/还原还是通过调整框架大小,您都会收到通知。听起来您只是希望JInternalFrame跟随JFrame的状态。为什么不将JInternalFrame设置为最大化
jInternalFrame.setMaximum( true );
我在setSize之后调用了jDesktopPane1.repaint(),但它仍然像我之前所说的那样。我明白了。我重写了JFrame的paint方法,并在paint方法中调用setSize方法,它确实有效。谢谢不,不,不,您不应该为此重写frames paint()方法。绘画的方法是绘画。它不用于更改添加到框架中的组件的属性。