Internal Frames:
JInternalFrame, JDesktopPane, and Related Classes

Other Swing Changes

Internal Frames Invisible By Default

In v 1.2 internal frames were visible by default; now they start out invisible. To make a JInternalFrame appear onscreen, use this code:

Why the change? The rule for default visibility in Swing is that only top-level components, such as JFrame and JDialog, have default visibility false; the remaining components have default visibility true. This is so that once a JFrame is constructed, one call to setVisible(true) on the JFrame will show it and all of its contents.

Although JInternalFrame is not really a top-level component, it needs to behave like a JFrame in many ways. In particular, it needs to fire JInternalFrame events corresponding to Window events on JFrames. One such event, INTERNAL_FRAME_OPENED, is fired in response to the initial visibility change from false to true; with no such change prior to version 1.3, the event wasn't being fired.

To fix this bug, and to make JInternalFrame more compatible with its heavyweight cousin JFrame, the default visibility of JInternalFrame changed to false beginning with version 1.3 of the Java 2 Platform. Therefore, to show an internal frame, just call setVisible(true) after adding the frame to its parent.

Added JInternalFrame setLayer(int layer) Method

JInternalFrame's setLayer() method takes an int, so that the beans introspector recognizes this as a property.


Added protected BasicInternalFrameUI.uninstallListeners() Method

Previously BasicInternalFrameTitlePane did not remove its listeners when no longer needed (thus becoming a memory leak). This behavior is now provided.


JInternalFrame "closed" Property

  1. The default setting for defaultCloseOperation has been changed from HIDE_ON_CLOSE to DISPOSE_ON_CLOSE. This change is provided so that clients who want to use only the vetoable property mechanism (which is the simplest, and which we encourage) can just do so, without having to set defaultCloseOperation.
  2. JInternalFrame's doDefaultCloseAction method has been changed from private to public. This is because the UI has to be able to invoke it. In the past, the UI just invoked JInternalFrame's public setClosed method, which called doDefaultCloseAction. But setClosed is used for programmatically closing frames, and thus should not call doDefaultCloseAction, because defaultCloseOperation is defined only for user-initiated close operations.


JInternalFrame Normal Bounds

Getting the normal dimensions of an internal frame is now possible through a new method to JInternalFrame: getNormalBounds()


Added getFocusOwner Method to JInternalFrame

New method for JInternalFrame:

Added getInternalFrame method to InternalFrameEvent

New method to InternalFrameEvent:

MetalInternalFrameTitlePane Class is now public


Added restoreSubcomponentFocus Method to JInternalFrame

New method to JInternalFrame:

Added setDragMode Method to JDesktopPane

New method to JDesktopPane:

Copyright © 1999 Sun Microsystems, Inc. All Rights Reserved.

Please send comments to: This is not a subscription list.
Java Software