APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.swing

public Class JDesktopPane

extends JLayeredPane
implements Accessible
Class Inheritance
All Implemented Interfaces
javax.accessibility.Accessible
Annotations
@JavaBean
defaultProperty:UI
@SuppressWarnings:serial
Imports
java.awt.Component, .Container, java.beans.BeanProperty, .JavaBean, .PropertyVetoException, java.io.IOException, .ObjectOutputStream, .Serial, java.util.ArrayList, .Collection, .LinkedHashSet, .List, .Set, .TreeSet, javax.accessibility.Accessible, .AccessibleContext, .AccessibleRole, javax.swing.plaf.DesktopPaneUI

A container used to create a multiple-document interface or a virtual desktop. You create JInternalFrame objects and add them to the JDesktopPane. JDesktopPane extends JLayeredPane to manage the potentially overlapping internal frames. It also maintains a reference to an instance of DesktopManager that is set by the UI class for the current look and feel (L&F). Note that JDesktopPane does not support borders.

This class is normally used as the parent of JInternalFrames to provide a pluggable DesktopManager object to the JInternalFrames. The installUI of the L&F specific implementation is responsible for setting the desktopManager variable appropriately. When the parent of a JInternalFrame is a JDesktopPane, it should delegate most of its behavior to the desktopManager (closing, resizing, etc).

For further documentation and examples see How to Use Internal Frames, a section in The Java Tutorial.

Warning

Swing is not thread safe. For more information see Swing's Threading Policy.

Warning

Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans has been added to the java.beans package. Please see java.beans.XMLEncoder.

Author
David Kloba
Since
1.2
See Also
JInternalFrame, JInternalFrame.JDesktopIcon, DesktopManager

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class
JDesktopPane.AccessibleJDesktopPane

This class implements accessibility support for the JDesktopPane class.

private static class

Field Summary

Modifier and TypeField and Description
private boolean
private boolean
pack-priv transient DesktopManager
private int
private boolean
private transient List<JInternalFrame>
public static final int
LIVE_DRAG_MODE

Indicates that the entire contents of the item being dragged should appear inside the desktop pane.

public static final int
OUTLINE_DRAG_MODE

Indicates that an outline only of the item being dragged should appear inside the desktop pane.

private transient JInternalFrame
private static final String
Inherited from javax.swing.JLayeredPane:
DEFAULT_LAYERDRAG_LAYERFRAME_CONTENT_LAYERLAYER_PROPERTYMODAL_LAYERPALETTE_LAYERPOPUP_LAYER

Constructor Summary

AccessConstructor and Description
public
JDesktopPane()

Creates a new JDesktopPane.

Method Summary

Modifier and TypeMethod and Description
protected void
addImpl(Component comp, Object constraints, int index)

Overrides javax.swing.JLayeredPane.addImpl.

Adds the specified component to this container at the specified index.

private void
public AccessibleContext

Returns:

an AccessibleJDesktopPane that serves as the AccessibleContext of this JDesktopPane
getAccessibleContext
()

Overrides javax.swing.JLayeredPane.getAccessibleContext.

Implements javax.accessibility.Accessible.getAccessibleContext.

Gets the AccessibleContext associated with this JDesktopPane.

public JInternalFrame[]

Returns:

an array of JInternalFrame objects
getAllFrames
()

Returns all JInternalFrames currently displayed in the desktop.

private static Collection<JInternalFrame>
public JInternalFrame[]

Returns:

an array of JInternalFrame objects
getAllFramesInLayer
(int
an int specifying the desktop layer
layer
)

Returns all JInternalFrames currently displayed in the specified layer of the desktop.

public DesktopManager

Returns:

the DesktopManger that handles desktop-specific UI actions
getDesktopManager
()

Returns the DesktopManger that handles desktop-specific UI actions.

public int

Returns:

either Live_DRAG_MODE or OUTLINE_DRAG_MODE
getDragMode
()

Gets the current "dragging style" used by the desktop pane.

private List<JInternalFrame>
private JInternalFrame
getNextFrame(JInternalFrame f, boolean forward)

pack-priv JInternalFrame
public JInternalFrame

Returns:

the currently active JInternalFrame or null
getSelectedFrame
()

Returns the currently active JInternalFrame in this JDesktopPane, or null if no JInternalFrame is currently active.

private JInternalFrame
public DesktopPaneUI

Returns:

the DesktopPaneUI object that renders this component
getUI
()

Overrides javax.swing.JComponent.getUI.

Returns the L&F object that renders this component.

public String

Returns:

the string "DesktopPaneUI"
getUIClassID
()

Overrides javax.swing.JComponent.getUIClassID.

Returns the name of the L&F class that renders this component.

protected String

Returns:

a string representation of this JDesktopPane
paramString
()

Overrides javax.swing.JLayeredPane.paramString.

Returns a string representation of this JDesktopPane.

public void
remove(Component comp)

Overrides java.awt.Container.remove.

Removes the specified component from this container.

public void
remove(int index)

Overrides javax.swing.JLayeredPane.remove.

Remove the indexed component from this pane.

public void
removeAll()

Overrides javax.swing.JLayeredPane.removeAll.

Removes all the components from this container.

public JInternalFrame

Returns:

the JInternalFrame that was selected or null if nothing was selected
selectFrame
(boolean
a boolean indicating which direction to select in; true for forward, false for backward
forward
)

Selects the next JInternalFrame in this desktop pane.

pack-priv void
public void
setComponentZOrder(Component comp, int index)

Overrides java.awt.Container.setComponentZOrder.

Moves the specified component to the specified z-order index in the container.

public void
setDesktopManager(DesktopManager
the DesktopManager to use
d
)

Sets the DesktopManger that will handle desktop-specific UI actions.

public void
setDragMode(int
the style of drag to use for items in the Desktop
dragMode
)

Sets the "dragging style" used by the desktop pane.

public void
setSelectedFrame(JInternalFrame
the internal frame that's currently selected
f
)

Sets the currently active JInternalFrame in this JDesktopPane.

public void
setUI(DesktopPaneUI
the DesktopPaneUI L&F object
ui
)

Sets the L&F object that renders this component.

pack-priv void
private void
public void
updateUI()

Overrides javax.swing.JComponent.updateUI.

Notification from the UIManager that the L&F has changed.

private void
private void
writeObject(ObjectOutputStream s)

Hides javax.swing.JComponent.writeObject.

See readObject() and writeObject() in JComponent for more information about serialization in Swing.

Inherited from javax.swing.JLayeredPane:
getComponentCountInLayergetComponentsInLayergetComponentToLayergetIndexOfgetLayergetLayergetLayeredPaneAbovegetObjectForLayergetPositionhighestLayerinsertIndexForLayerisOptimizedDrawingEnabledlowestLayermoveToBackmoveToFrontpaintputLayersetLayersetLayersetPosition

Field Detail

componentOrderChangedback to summary
private boolean componentOrderChanged
componentOrderCheckingEnabledback to summary
private boolean componentOrderCheckingEnabled
desktopManagerback to summary
pack-priv transient DesktopManager desktopManager
dragModeback to summary
private int dragMode
dragModeSetback to summary
private boolean dragModeSet
framesCacheback to summary
private transient List<JInternalFrame> framesCache
LIVE_DRAG_MODEback to summary
public static final int LIVE_DRAG_MODE

Indicates that the entire contents of the item being dragged should appear inside the desktop pane.

See Also
OUTLINE_DRAG_MODE, setDragMode
OUTLINE_DRAG_MODEback to summary
public static final int OUTLINE_DRAG_MODE

Indicates that an outline only of the item being dragged should appear inside the desktop pane.

See Also
LIVE_DRAG_MODE, setDragMode
selectedFrameback to summary
private transient JInternalFrame selectedFrame
uiClassIDback to summary
private static final String uiClassID

Hides javax.swing.JComponent.uiClassID.

See Also
getUIClassID, readObject

Constructor Detail

JDesktopPaneback to summary
public JDesktopPane()

Creates a new JDesktopPane.

Method Detail

addImplback to summary
protected void addImpl(Component comp, Object constraints, int index)

Overrides javax.swing.JLayeredPane.addImpl.

Doc from java.awt.Container.addImpl.

Adds the specified component to this container at the specified index. This method also notifies the layout manager to add the component to this container's layout using the specified constraints object via the addLayoutComponent method.

The constraints are defined by the particular layout manager being used. For example, the BorderLayout class defines five constraints: BorderLayout.NORTH, BorderLayout.SOUTH, BorderLayout.EAST, BorderLayout.WEST, and BorderLayout.CENTER.

The GridBagLayout class requires a GridBagConstraints object. Failure to pass the correct type of constraints object results in an IllegalArgumentException.

If the current layout manager implements LayoutManager2, then LayoutManager2#addLayoutComponent(Component, Object) is invoked on it. If the current layout manager does not implement LayoutManager2, and constraints is a String, then LayoutManager#addLayoutComponent(String, Component) is invoked on it.

If the component is not an ancestor of this container and has a non-null parent, it is removed from its current parent before it is added to this container.

This is the method to override if a program needs to track every add request to a container as all other add methods defer to this one. An overriding method should usually include a call to the superclass's version of the method:

super.addImpl(comp, constraints, index)

This method changes layout-related information, and therefore, invalidates the component hierarchy. If the container has already been displayed, the hierarchy must be validated thereafter in order to display the added component.

Since
1.6
checkComponentAttributesback to summary
private void checkComponentAttributes(Component comp)
getAccessibleContextback to summary
public AccessibleContext getAccessibleContext()

Overrides javax.swing.JLayeredPane.getAccessibleContext.

Implements javax.accessibility.Accessible.getAccessibleContext.

Gets the AccessibleContext associated with this JDesktopPane. For desktop panes, the AccessibleContext takes the form of an AccessibleJDesktopPane. A new AccessibleJDesktopPane instance is created if necessary.

Returns:AccessibleContext

an AccessibleJDesktopPane that serves as the AccessibleContext of this JDesktopPane

Annotations
@BeanProperty
bound:false
getAllFramesback to summary
public JInternalFrame[] getAllFrames()

Returns all JInternalFrames currently displayed in the desktop. Returns iconified frames as well as expanded frames.

Returns:JInternalFrame[]

an array of JInternalFrame objects

Annotations
@BeanProperty
bound:false
getAllFramesback to summary
private static Collection<JInternalFrame> getAllFrames(Container parent)
getAllFramesInLayerback to summary
public JInternalFrame[] getAllFramesInLayer(int layer)

Returns all JInternalFrames currently displayed in the specified layer of the desktop. Returns iconified frames as well expanded frames.

Parameters
layer:int

an int specifying the desktop layer

Returns:JInternalFrame[]

an array of JInternalFrame objects

See Also
JLayeredPane
getDesktopManagerback to summary
public DesktopManager getDesktopManager()

Returns the DesktopManger that handles desktop-specific UI actions.

Returns:DesktopManager

the DesktopManger that handles desktop-specific UI actions

getDragModeback to summary
public int getDragMode()

Gets the current "dragging style" used by the desktop pane.

Returns:int

either Live_DRAG_MODE or OUTLINE_DRAG_MODE

Since
1.3
See Also
setDragMode
getFramesback to summary
private List<JInternalFrame> getFrames()
getNextFrameback to summary
private JInternalFrame getNextFrame(JInternalFrame f, boolean forward)
getNextFrameback to summary
pack-priv JInternalFrame getNextFrame(JInternalFrame f)
getSelectedFrameback to summary
public JInternalFrame getSelectedFrame()

Returns the currently active JInternalFrame in this JDesktopPane, or null if no JInternalFrame is currently active.

Returns:JInternalFrame

the currently active JInternalFrame or null

Since
1.3
getTopInternalFrameback to summary
private JInternalFrame getTopInternalFrame()
getUIback to summary
public DesktopPaneUI getUI()

Overrides javax.swing.JComponent.getUI.

Returns the L&F object that renders this component.

Returns:DesktopPaneUI

the DesktopPaneUI object that renders this component

getUIClassIDback to summary
public String getUIClassID()

Overrides javax.swing.JComponent.getUIClassID.

Returns the name of the L&F class that renders this component.

Returns:String

the string "DesktopPaneUI"

Annotations
@BeanProperty
bound:false
See Also
JComponent#getUIClassID, UIDefaults#getUI
paramStringback to summary
protected String paramString()

Overrides javax.swing.JLayeredPane.paramString.

Returns a string representation of this JDesktopPane. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null.

Returns:String

a string representation of this JDesktopPane

removeback to summary
public void remove(Component comp)

Overrides java.awt.Container.remove.

Doc from java.awt.Container.remove.

Removes the specified component from this container. This method also notifies the layout manager to remove the component from this container's layout via the removeLayoutComponent method.

This method changes layout-related information, and therefore, invalidates the component hierarchy. If the container has already been displayed, the hierarchy must be validated thereafter in order to reflect the changes.

Annotations
@Override
removeback to summary
public void remove(int index)

Overrides javax.swing.JLayeredPane.remove.

Doc from javax.swing.JLayeredPane.remove.

Remove the indexed component from this pane. This is the absolute index, ignoring layers.

Since
1.6
removeAllback to summary
public void removeAll()

Overrides javax.swing.JLayeredPane.removeAll.

Doc from javax.swing.JLayeredPane.removeAll.

Removes all the components from this container.

Since
1.6
selectFrameback to summary
public JInternalFrame selectFrame(boolean forward)

Selects the next JInternalFrame in this desktop pane.

Parameters
forward:boolean

a boolean indicating which direction to select in; true for forward, false for backward

Returns:JInternalFrame

the JInternalFrame that was selected or null if nothing was selected

Since
1.6
setComponentOrderCheckingEnabledback to summary
pack-priv void setComponentOrderCheckingEnabled(boolean enable)
setComponentZOrderback to summary
public void setComponentZOrder(Component comp, int index)

Overrides java.awt.Container.setComponentZOrder.

Doc from java.awt.Container.setComponentZOrder.

Moves the specified component to the specified z-order index in the container. The z-order determines the order that components are painted; the component with the highest z-order paints first and the component with the lowest z-order paints last. Where components overlap, the component with the lower z-order paints over the component with the higher z-order.

If the component is a child of some other container, it is removed from that container before being added to this container. The important difference between this method and java.awt.Container.add(Component, int) is that this method doesn't call removeNotify on the component while removing it from its previous container unless necessary and when allowed by the underlying native windowing system. This way, if the component has the keyboard focus, it maintains the focus when moved to the new position.

This property is guaranteed to apply only to lightweight non-Container components.

This method changes layout-related information, and therefore, invalidates the component hierarchy.

Note

Not all platforms support changing the z-order of heavyweight components from one container into another without the call to removeNotify. There is no way to detect whether a platform supports this, so developers shouldn't make any assumptions.

Since
1.6
setDesktopManagerback to summary
public void setDesktopManager(DesktopManager d)

Sets the DesktopManger that will handle desktop-specific UI actions. This may be overridden by LookAndFeel.

Parameters
d:DesktopManager

the DesktopManager to use

Annotations
@BeanProperty
description:Desktop manager to handle the internal frames in the desktop pane.
setDragModeback to summary
public void setDragMode(int dragMode)

Sets the "dragging style" used by the desktop pane. You may want to change to one mode or another for performance or aesthetic reasons.

Parameters
dragMode:int

the style of drag to use for items in the Desktop

Annotations
@BeanProperty
enumerationValues:JDesktopPane.LIVE_DRAG_MODE, JDesktopPane.OUTLINE_DRAG_MODE
description:Dragging style for internal frame children.
Since
1.3
See Also
LIVE_DRAG_MODE, OUTLINE_DRAG_MODE
setSelectedFrameback to summary
public void setSelectedFrame(JInternalFrame f)

Sets the currently active JInternalFrame in this JDesktopPane. This method is used to bridge the package gap between JDesktopPane and the platform implementation code and should not be called directly. To visually select the frame the client must call JInternalFrame.setSelected(true) to activate the frame.

Parameters
f:JInternalFrame

the internal frame that's currently selected

Since
1.3
See Also
JInternalFrame#setSelected(boolean)
setUIback to summary
public void setUI(DesktopPaneUI ui)

Sets the L&F object that renders this component.

Parameters
ui:DesktopPaneUI

the DesktopPaneUI L&F object

Annotations
@BeanProperty
hidden:true
visualUpdate:true
description:The UI object that implements the Component\'s LookAndFeel.
See Also
UIDefaults#getUI
setUIPropertyback to summary
pack-priv void setUIProperty(String propertyName, Object value)

Overrides javax.swing.JComponent.setUIProperty.

updateFramesCacheback to summary
private void updateFramesCache()
updateUIback to summary
public void updateUI()

Overrides javax.swing.JComponent.updateUI.

Notification from the UIManager that the L&F has changed. Replaces the current UI object with the latest version from the UIManager.

See Also
JComponent#updateUI
verifyFramesCacheback to summary
private void verifyFramesCache()
writeObjectback to summary
private void writeObject(ObjectOutputStream s) throws IOException

Hides javax.swing.JComponent.writeObject.

See readObject() and writeObject() in JComponent for more information about serialization in Swing.

Annotations
@Serial
Exceptions
IOException:

Doc from java.awt.Container.writeObject.

if an I/O error occurs

javax.swing back to summary

protected Class JDesktopPane.AccessibleJDesktopPane

extends AccessibleJComponent
Class Inheritance
Annotations
@SuppressWarnings:serial

This class implements accessibility support for the JDesktopPane class. It provides an implementation of the Java Accessibility API appropriate to desktop pane user-interface elements.

Warning

Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans has been added to the java.beans package. Please see java.beans.XMLEncoder.

Field Summary

Inherited from javax.swing.JComponent.AccessibleJComponent:
accessibleFocusHandler

Constructor Summary

AccessConstructor and Description
protected
AccessibleJDesktopPane()

Constructs an AccessibleJDesktopPane.

Method Summary

Modifier and TypeMethod and Description
public AccessibleRole

Returns:

an instance of AccessibleRole describing the role of the object
getAccessibleRole
()

Overrides javax.swing.JComponent.AccessibleJComponent.getAccessibleRole.

Get the role of this object.

Inherited from javax.swing.JComponent.AccessibleJComponent:
addPropertyChangeListenergetAccessibleChildgetAccessibleChildrenCountgetAccessibleDescriptiongetAccessibleExtendedComponentgetAccessibleKeyBindinggetAccessibleNamegetAccessibleStateSetgetBorderTitlegetTitledBorderTextgetToolTipTextremovePropertyChangeListener

Constructor Detail

AccessibleJDesktopPaneback to summary
protected AccessibleJDesktopPane()

Constructs an AccessibleJDesktopPane.

Method Detail

getAccessibleRoleback to summary
public AccessibleRole getAccessibleRole()

Overrides javax.swing.JComponent.AccessibleJComponent.getAccessibleRole.

Get the role of this object.

Returns:AccessibleRole

an instance of AccessibleRole describing the role of the object

See Also
AccessibleRole
javax.swing back to summary

private Class JDesktopPane.ComponentPosition

extends Object
implements Comparable<JDesktopPane.ComponentPosition>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable

Field Summary

Modifier and TypeField and Description
private final JInternalFrame
private final int
private final int

Constructor Summary

AccessConstructor and Description
pack-priv
ComponentPosition(JInternalFrame component, int layer, int zOrder)

Method Summary

Modifier and TypeMethod and Description
public int
compareTo(JDesktopPane.ComponentPosition o)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

componentback to summary
private final JInternalFrame component
layerback to summary
private final int layer
zOrderback to summary
private final int zOrder

Constructor Detail

ComponentPositionback to summary
pack-priv ComponentPosition(JInternalFrame component, int layer, int zOrder)

Method Detail

compareToback to summary
public int compareTo(JDesktopPane.ComponentPosition o)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.