FileDocCategorySizeDatePackage
JDesktopPane.javaAPI DocJava SE 5 API13592Fri Aug 26 14:57:54 BST 2005javax.swing

JDesktopPane

public class JDesktopPane extends JLayeredPane implements Accessible
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: 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 see {@link java.beans.XMLEncoder}.

see
JInternalFrame
see
JInternalFrame.JDesktopIcon
see
DesktopManager
version
1.51 12/19/03
author
David Kloba

Fields Summary
private static final String
uiClassID
transient DesktopManager
desktopManager
private transient JInternalFrame
selectedFrame
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 int
dragMode
private boolean
dragModeSet
Constructors Summary
public JDesktopPane()
Creates a new JDesktopPane.


              
      
        setFocusCycleRoot(true);

        setFocusTraversalPolicy(new LayoutFocusTraversalPolicy() {
            public Component getDefaultComponent(Container c) {
                JInternalFrame jifArray[] = getAllFrames();
                Component comp = null;
                for (int i = 0; i < jifArray.length; i++) {
                    comp = jifArray[i].getFocusTraversalPolicy().getDefaultComponent(jifArray[i]);
                    if (comp != null) {
                        break;
                    }
                }
                return comp;
            }
        });
        updateUI();
    
Methods Summary
public javax.accessibility.AccessibleContextgetAccessibleContext()
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.

return
an AccessibleJDesktopPane that serves as the AccessibleContext of this JDesktopPane

        if (accessibleContext == null) {
            accessibleContext = new AccessibleJDesktopPane();
        }
        return accessibleContext;
    
public javax.swing.JInternalFrame[]getAllFrames()
Returns all JInternalFrames currently displayed in the desktop. Returns iconified frames as well as expanded frames.

return
an array of JInternalFrame objects

        int i, count;
        JInternalFrame[] results;
        Vector vResults = new Vector(10);
        Object next, tmp;

        count = getComponentCount();
        for(i = 0; i < count; i++) {
            next = getComponent(i);
            if(next instanceof JInternalFrame)
                vResults.addElement(next);
            else if(next instanceof JInternalFrame.JDesktopIcon)  {
                tmp = ((JInternalFrame.JDesktopIcon)next).getInternalFrame();
                if(tmp != null)
                    vResults.addElement(tmp);
            }
        }

        results = new JInternalFrame[vResults.size()];
        vResults.copyInto(results);

        return results;
    
public javax.swing.JInternalFrame[]getAllFramesInLayer(int layer)
Returns all JInternalFrames currently displayed in the specified layer of the desktop. Returns iconified frames as well expanded frames.

param
layer an int specifying the desktop layer
return
an array of JInternalFrame objects
see
JLayeredPane

        int i, count;
        JInternalFrame[] results;
        Vector vResults = new Vector(10);
        Object next, tmp;

        count = getComponentCount();
        for(i = 0; i < count; i++) {
            next = getComponent(i);
            if(next instanceof JInternalFrame) {
                if(((JInternalFrame)next).getLayer() == layer)
                    vResults.addElement(next);
            } else if(next instanceof JInternalFrame.JDesktopIcon)  {
                tmp = ((JInternalFrame.JDesktopIcon)next).getInternalFrame();
                if(tmp != null && ((JInternalFrame)tmp).getLayer() == layer)
                    vResults.addElement(tmp);
            }
        }

        results = new JInternalFrame[vResults.size()];
        vResults.copyInto(results);

        return results;
    
public javax.swing.DesktopManagergetDesktopManager()
Returns the DesktopManger that handles desktop-specific UI actions.

        return desktopManager;
    
public intgetDragMode()
Gets the current "dragging style" used by the desktop pane.

return
either Live_DRAG_MODE or OUTLINE_DRAG_MODE
see
#setDragMode

         return dragMode;
     
public javax.swing.JInternalFramegetSelectedFrame()
Returns the currently active JInternalFrame in this JDesktopPane, or null if no JInternalFrame is currently active.

return
the currently active JInternalFrame or null
since
1.3

      return selectedFrame;
    
public javax.swing.plaf.DesktopPaneUIgetUI()
Returns the L&F object that renders this component.

return
the DesktopPaneUI object that renders this component

        return (DesktopPaneUI)ui;
    
public java.lang.StringgetUIClassID()
Returns the name of the L&F class that renders this component.

return
the string "DesktopPaneUI"
see
JComponent#getUIClassID
see
UIDefaults#getUI

        return uiClassID;
    
public booleanisOpaque()
Returns true to indicate that this component paints every pixel in its range. (In other words, it does not have a transparent background or foreground.)

return
true
see
JComponent#isOpaque

        return true;
    
protected java.lang.StringparamString()
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.

return
a string representation of this JDesktopPane

	String desktopManagerString = (desktopManager != null ?
				       desktopManager.toString() : "");

	return super.paramString() +
	",desktopManager=" + desktopManagerString;
    
public voidsetDesktopManager(javax.swing.DesktopManager d)
Sets the DesktopManger that will handle desktop-specific UI actions.

param
d the DesktopManager to use
beaninfo
bound: true description: Desktop manager to handle the internal frames in the desktop pane.

        DesktopManager oldValue = desktopManager;
        desktopManager = d;
        firePropertyChange("desktopManager", oldValue, desktopManager);
    
public voidsetDragMode(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.

param
dragMode the style of drag to use for items in the Desktop
see
#LIVE_DRAG_MODE
see
#OUTLINE_DRAG_MODE
beaninfo
bound: true description: Dragging style for internal frame children. enum: LIVE_DRAG_MODE JDesktopPane.LIVE_DRAG_MODE OUTLINE_DRAG_MODE JDesktopPane.OUTLINE_DRAG_MODE

        int oldDragMode = this.dragMode;
        this.dragMode = dragMode;
        firePropertyChange("dragMode", oldDragMode, this.dragMode);
	dragModeSet = true;
     
public voidsetSelectedFrame(javax.swing.JInternalFrame f)
Sets the currently active JInternalFrame in this JDesktopPane.

param
f the internal frame that's currently selected
since
1.3

      selectedFrame = f;
    
public voidsetUI(javax.swing.plaf.DesktopPaneUI ui)
Sets the L&F object that renders this component.

param
ui the DesktopPaneUI L&F object
see
UIDefaults#getUI
beaninfo
bound: true hidden: true attribute: visualUpdate true description: The UI object that implements the Component's LookAndFeel.

        super.setUI(ui);
    
voidsetUIProperty(java.lang.String propertyName, java.lang.Object value)

        if (propertyName == "dragMode") {
	    if (!dragModeSet) {
		setDragMode(((Integer)value).intValue());
		dragModeSet = false;
	    }
	} else {
	    super.setUIProperty(propertyName, value);
	}
    
public voidupdateUI()
Notification from the UIManager that the L&F has changed. Replaces the current UI object with the latest version from the UIManager.

see
JComponent#updateUI

        setUI((DesktopPaneUI)UIManager.getUI(this));
    
private voidwriteObject(java.io.ObjectOutputStream s)
See readObject() and writeObject() in JComponent for more information about serialization in Swing.

        s.defaultWriteObject();
        if (getUIClassID().equals(uiClassID)) {
            byte count = JComponent.getWriteObjCounter(this);
            JComponent.setWriteObjCounter(this, --count);
            if (count == 0 && ui != null) {
                ui.installUI(this);
            }
        }