- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JLayeredPane
-
- javax.swing.JDesktopPane
-
- All Implemented Interfaces:
- ImageObserver, MenuContainer, Serializable, Accessible
public class JDesktopPane extends JLayeredPane implements Accessible
A container used to create a multiple-document interface or a virtual desktop. You createJInternalFrame
objects and add them to theJDesktopPane
.JDesktopPane
extendsJLayeredPane
to manage the potentially overlapping internal frames. It also maintains a reference to an instance ofDesktopManager
that is set by the UI class for the current look and feel (L&F). Note thatJDesktopPane
does not support borders.This class is normally used as the parent of
JInternalFrames
to provide a pluggableDesktopManager
object to theJInternalFrames
. TheinstallUI
of the L&F specific implementation is responsible for setting thedesktopManager
variable appropriately. When the parent of aJInternalFrame
is aJDesktopPane
, it should delegate most of its behavior to thedesktopManager
(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 JavaBeansTM has been added to the
java.beans
package. Please seeXMLEncoder
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description protected class
JDesktopPane.AccessibleJDesktopPane
This class implements accessibility support for theJDesktopPane
class.-
Nested classes/interfaces inherited from class javax.swing.JLayeredPane
JLayeredPane.AccessibleJLayeredPane
-
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
-
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
-
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
-
Field Summary
Fields Modifier and Type Field and Description static int
LIVE_DRAG_MODE
Indicates that the entire contents of the item being dragged should appear inside the desktop pane.static int
OUTLINE_DRAG_MODE
Indicates that an outline only of the item being dragged should appear inside the desktop pane.-
Fields inherited from class javax.swing.JLayeredPane
DEFAULT_LAYER, DRAG_LAYER, FRAME_CONTENT_LAYER, LAYER_PROPERTY, MODAL_LAYER, PALETTE_LAYER, POPUP_LAYER
-
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
-
-
Constructor Summary
Constructors Constructor and Description JDesktopPane()
Creates a newJDesktopPane
.
-
Method Summary
Methods Modifier and Type Method and Description protected void
addImpl(Component comp, Object constraints, int index)
Adds the specified component to this container at the specified index.AccessibleContext
getAccessibleContext()
Gets theAccessibleContext
associated with thisJDesktopPane
.JInternalFrame[]
getAllFrames()
Returns allJInternalFrames
currently displayed in the desktop.JInternalFrame[]
getAllFramesInLayer(int layer)
Returns allJInternalFrames
currently displayed in the specified layer of the desktop.DesktopManager
getDesktopManager()
Returns theDesktopManger
that handles desktop-specific UI actions.int
getDragMode()
Gets the current "dragging style" used by the desktop pane.JInternalFrame
getSelectedFrame()
Returns the currently activeJInternalFrame
in thisJDesktopPane
, ornull
if noJInternalFrame
is currently active.DesktopPaneUI
getUI()
Returns the L&F object that renders this component.String
getUIClassID()
Returns the name of the L&F class that renders this component.protected String
paramString()
Returns a string representation of thisJDesktopPane
.void
remove(Component comp)
Removes the specified component from this container.void
remove(int index)
Remove the indexed component from this pane.void
removeAll()
Removes all the components from this container.JInternalFrame
selectFrame(boolean forward)
Selects the nextJInternalFrame
in this desktop pane.void
setComponentZOrder(Component comp, int index)
Moves the specified component to the specified z-order index in the container.void
setDesktopManager(DesktopManager d)
Sets theDesktopManger
that will handle desktop-specific UI actions.void
setDragMode(int dragMode)
Sets the "dragging style" used by the desktop pane.void
setSelectedFrame(JInternalFrame f)
Sets the currently activeJInternalFrame
in thisJDesktopPane
.void
setUI(DesktopPaneUI ui)
Sets the L&F object that renders this component.void
updateUI()
Notification from theUIManager
that the L&F has changed.-
Methods inherited from class javax.swing.JLayeredPane
getComponentCountInLayer, getComponentsInLayer, getComponentToLayer, getIndexOf, getLayer, getLayer, getLayeredPaneAbove, getObjectForLayer, getPosition, highestLayer, insertIndexForLayer, isOptimizedDrawingEnabled, lowestLayer, moveToBack, moveToFront, paint, putLayer, setLayer, setLayer, setPosition
-
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
-
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, removeContainerListener, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
-
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
LIVE_DRAG_MODE
public static final int LIVE_DRAG_MODE
Indicates that the entire contents of the item being dragged should appear inside the desktop pane.
-
OUTLINE_DRAG_MODE
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(int)
, Constant Field Values
-
-
Method Detail
-
getUI
public DesktopPaneUI getUI()
Returns the L&F object that renders this component.- Returns:
- the
DesktopPaneUI
object that renders this component
-
setUI
public void setUI(DesktopPaneUI ui)
Sets the L&F object that renders this component.- Parameters:
ui
- the DesktopPaneUI L&F object- See Also:
UIDefaults.getUI(javax.swing.JComponent)
-
setDragMode
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
- the style of drag to use for items in the Desktop- Since:
- 1.3
- See Also:
LIVE_DRAG_MODE
,OUTLINE_DRAG_MODE
-
getDragMode
public int getDragMode()
Gets the current "dragging style" used by the desktop pane.- Returns:
- either
Live_DRAG_MODE
orOUTLINE_DRAG_MODE
- Since:
- 1.3
- See Also:
setDragMode(int)
-
getDesktopManager
public DesktopManager getDesktopManager()
Returns theDesktopManger
that handles desktop-specific UI actions.
-
setDesktopManager
public void setDesktopManager(DesktopManager d)
Sets theDesktopManger
that will handle desktop-specific UI actions. This may be overridden byLookAndFeel
.- Parameters:
d
- theDesktopManager
to use
-
updateUI
public void updateUI()
Notification from theUIManager
that the L&F has changed. Replaces the current UI object with the latest version from theUIManager
.- Overrides:
updateUI
in classJComponent
- See Also:
JComponent.updateUI()
-
getUIClassID
public String getUIClassID()
Returns the name of the L&F class that renders this component.- Overrides:
getUIClassID
in classJComponent
- Returns:
- the string "DesktopPaneUI"
- See Also:
JComponent.getUIClassID()
,UIDefaults.getUI(javax.swing.JComponent)
-
getAllFrames
public JInternalFrame[] getAllFrames()
Returns allJInternalFrames
currently displayed in the desktop. Returns iconified frames as well as expanded frames.- Returns:
- an array of
JInternalFrame
objects
-
getSelectedFrame
public JInternalFrame getSelectedFrame()
Returns the currently activeJInternalFrame
in thisJDesktopPane
, ornull
if noJInternalFrame
is currently active.- Returns:
- the currently active
JInternalFrame
ornull
- Since:
- 1.3
-
setSelectedFrame
public void setSelectedFrame(JInternalFrame f)
Sets the currently activeJInternalFrame
in thisJDesktopPane
. 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
- the internal frame that's currently selected- Since:
- 1.3
- See Also:
JInternalFrame.setSelected(boolean)
-
getAllFramesInLayer
public JInternalFrame[] getAllFramesInLayer(int layer)
Returns allJInternalFrames
currently displayed in the specified layer of the desktop. Returns iconified frames as well expanded frames.- Parameters:
layer
- an int specifying the desktop layer- Returns:
- an array of
JInternalFrame
objects - See Also:
JLayeredPane
-
remove
public void remove(Component comp)
Removes the specified component from this container. This method also notifies the layout manager to remove the component from this container's layout via theremoveLayoutComponent
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.
- Overrides:
remove
in classContainer
- Parameters:
comp
- the component to be removed- See Also:
Container.add(java.awt.Component)
,Container.invalidate()
,Container.validate()
,Container.remove(int)
-
selectFrame
public JInternalFrame selectFrame(boolean forward)
Selects the nextJInternalFrame
in this desktop pane.- Parameters:
forward
- a boolean indicating which direction to select in;true
for forward,false
for backward- Returns:
- the JInternalFrame that was selected or
null
if nothing was selected - Since:
- 1.6
-
addImpl
protected void addImpl(Component comp, Object constraints, int index)
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 theaddLayoutComponent
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
, andBorderLayout.CENTER
.The
GridBagLayout
class requires aGridBagConstraints
object. Failure to pass the correct type of constraints object results in anIllegalArgumentException
.If the current layout manager implements
LayoutManager2
, thenLayoutManager2.addLayoutComponent(Component,Object)
is invoked on it. If the current layout manager does not implementLayoutManager2
, and constraints is aString
, thenLayoutManager.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.
- Overrides:
addImpl
in classJLayeredPane
- Parameters:
comp
- the component to be addedconstraints
- an object expressing layout constraints for this componentindex
- the position in the container's list at which to insert the component, where-1
means append to the end- Since:
- 1.6
- See Also:
Container.add(Component)
,Container.add(Component, int)
,Container.add(Component, java.lang.Object)
,Container.invalidate()
,LayoutManager
,LayoutManager2
-
remove
public void remove(int index)
Remove the indexed component from this pane. This is the absolute index, ignoring layers.- Overrides:
remove
in classJLayeredPane
- Parameters:
index
- an int specifying the component to remove- Since:
- 1.6
- See Also:
JLayeredPane.getIndexOf(java.awt.Component)
-
removeAll
public void removeAll()
Removes all the components from this container.- Overrides:
removeAll
in classJLayeredPane
- Since:
- 1.6
- See Also:
Container.add(java.awt.Component)
,Container.remove(int)
,Container.invalidate()
-
setComponentZOrder
public void setComponentZOrder(Component comp, int index)
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 callremoveNotify
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.- Overrides:
setComponentZOrder
in classContainer
- Parameters:
comp
- the component to be movedindex
- the position in the container's list to insert the component, wheregetComponentCount()
appends to the end- Since:
- 1.6
- See Also:
Container.getComponentZOrder(java.awt.Component)
,Container.invalidate()
-
paramString
protected String paramString()
Returns a string representation of thisJDesktopPane
. 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 benull
.- Overrides:
paramString
in classJLayeredPane
- Returns:
- a string representation of this
JDesktopPane
-
getAccessibleContext
public AccessibleContext getAccessibleContext()
Gets theAccessibleContext
associated with thisJDesktopPane
. For desktop panes, theAccessibleContext
takes the form of anAccessibleJDesktopPane
. A newAccessibleJDesktopPane
instance is created if necessary.- Specified by:
getAccessibleContext
in interfaceAccessible
- Overrides:
getAccessibleContext
in classJLayeredPane
- Returns:
- an
AccessibleJDesktopPane
that serves as theAccessibleContext
of thisJDesktopPane
-
-
Document created the 11/06/2005, last modified the 04/03/2020
Source of the printed document:https://www.gaudry.be/en/java-api-rf-javax/swing/jdesktoppane.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.