FileDocCategorySizeDatePackage
JWindow.javaAPI DocJava SE 5 API19290Fri Aug 26 14:57:58 BST 2005javax.swing

JWindow

public class JWindow extends Window implements RootPaneContainer, Accessible
A JWindow is a container that can be displayed anywhere on the user's desktop. It does not have the title bar, window-management buttons, or other trimmings associated with a JFrame, but it is still a "first-class citizen" of the user's desktop, and can exist anywhere on it.

The JWindow component contains a JRootPane as its only child. The contentPane should be the parent of any children of the JWindow. As a conveniance add and its variants, remove and setLayout have been overridden to forward to the contentPane as necessary. This means you can write:

window.add(child);
And the child will be added to the contentPane. The contentPane will always be non-null. Attempting to set it to null will cause the JWindow to throw an exception. The default contentPane will have a BorderLayout manager set on it. Refer to {@link javax.swing.RootPaneContainer} for details on adding, removing and setting the LayoutManager of a JWindow.

Please see the {@link JRootPane} documentation for a complete description of the contentPane, glassPane, and layeredPane components.

In a multi-screen environment, you can create a JWindow on a different screen device. See {@link java.awt.Window} for more information.

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
JRootPane
beaninfo
attribute: isContainer true attribute: containerDelegate getContentPane description: A toplevel window which has no system border or controls.
version
1.60 12/19/03
author
David Kloba

Fields Summary
protected JRootPane
rootPane
The JRootPane instance that manages the contentPane and optional menuBar for this frame, as well as the glassPane.
protected boolean
rootPaneCheckingEnabled
If true then calls to add and setLayout will be forwarded to the contentPane. This is initially false, but is set to true when the JWindow is constructed.
protected AccessibleContext
accessibleContext
The accessible context property.
Constructors Summary
public JWindow()
Creates a window with no specified owner. This window will not be focusable.

This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale.

throws
HeadlessException if GraphicsEnvironment.isHeadless() returns true.
see
java.awt.GraphicsEnvironment#isHeadless
see
#isFocusableWindow
see
JComponent#getDefaultLocale


                                                             
      
        this((Frame)null);
    
public JWindow(GraphicsConfiguration gc)
Creates a window with the specified GraphicsConfiguration of a screen device. This window will not be focusable.

This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale.

param
gc the GraphicsConfiguration that is used to construct the new window with; if gc is null, the system default GraphicsConfiguration is assumed
throws
HeadlessException If GraphicsEnvironment.isHeadless() returns true.
throws
IllegalArgumentException if gc is not from a screen device.
see
java.awt.GraphicsEnvironment#isHeadless
see
#isFocusableWindow
see
JComponent#getDefaultLocale
since
1.3

        this(null, gc);
        super.setFocusableWindowState(false);
    
public JWindow(Frame owner)
Creates a window with the specified owner frame. If owner is null, the shared owner will be used and this window will not be focusable. Also, this window will not be focusable unless its owner is showing on the screen.

This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale.

param
owner the frame from which the window is displayed
throws
HeadlessException if GraphicsEnvironment.isHeadless() returns true.
see
java.awt.GraphicsEnvironment#isHeadless
see
#isFocusableWindow
see
JComponent#getDefaultLocale

        super(owner == null? SwingUtilities.getSharedOwnerFrame() : owner);
	if (owner == null) {
	    WindowListener ownerShutdownListener =
		(WindowListener)SwingUtilities.getSharedOwnerFrameShutdownListener();
 	    addWindowListener(ownerShutdownListener);
	}
        windowInit();
    
public JWindow(Window owner)
Creates a window with the specified owner window. This window will not be focusable unless its owner is showing on the screen. If owner is null, the shared owner will be used and this window will not be focusable.

This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale.

param
owner the window from which the window is displayed
throws
HeadlessException if GraphicsEnvironment.isHeadless() returns true.
see
java.awt.GraphicsEnvironment#isHeadless
see
#isFocusableWindow
see
JComponent#getDefaultLocale

        super(owner == null ? (Window)SwingUtilities.getSharedOwnerFrame() :
              owner);
	if (owner == null) {
	    WindowListener ownerShutdownListener =
		(WindowListener)SwingUtilities.getSharedOwnerFrameShutdownListener();
 	    addWindowListener(ownerShutdownListener);
	}
        windowInit();
    
public JWindow(Window owner, GraphicsConfiguration gc)
Creates a window with the specified owner window and GraphicsConfiguration of a screen device. If owner is null, the shared owner will be used and this window will not be focusable.

This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale.

param
owner the window from which the window is displayed
param
gc the GraphicsConfiguration that is used to construct the new window with; if gc is null, the system default GraphicsConfiguration is assumed, unless owner is also null, in which case the GraphicsConfiguration from the shared owner frame will be used.
throws
HeadlessException if GraphicsEnvironment.isHeadless() returns true.
throws
IllegalArgumentException if gc is not from a screen device.
see
java.awt.GraphicsEnvironment#isHeadless
see
#isFocusableWindow
see
JComponent#getDefaultLocale
since
1.3

        super(owner == null ? (Window)SwingUtilities.getSharedOwnerFrame() :
              owner, gc);
	if (owner == null) {
	    WindowListener ownerShutdownListener =
		(WindowListener)SwingUtilities.getSharedOwnerFrameShutdownListener();
 	    addWindowListener(ownerShutdownListener);
	}
        windowInit();
    
Methods Summary
protected voidaddImpl(java.awt.Component comp, java.lang.Object constraints, int index)
Adds the specified child Component. This method is overridden to conditionally forwad calls to the contentPane. By default, children are added to the contentPane instead of the frame, refer to {@link javax.swing.RootPaneContainer} for details.

param
comp the component to be enhanced
param
constraints the constraints to be respected
param
index the index
exception
IllegalArgumentException if index is invalid
exception
IllegalArgumentException if adding the container's parent to itself
exception
IllegalArgumentException if adding a window to a container
see
#setRootPaneCheckingEnabled
see
javax.swing.RootPaneContainer

        if(isRootPaneCheckingEnabled()) {
            getContentPane().add(comp, constraints, index);
        }
        else {
            super.addImpl(comp, constraints, index);
        }
    
protected javax.swing.JRootPanecreateRootPane()
Called by the constructor methods to create the default rootPane.

        JRootPane rp = new JRootPane();
        // NOTE: this uses setOpaque vs LookAndFeel.installProperty as there
        // is NO reason for the RootPane not to be opaque. For painting to
        // work the contentPane must be opaque, therefor the RootPane can
        // also be opaque.
        rp.setOpaque(true);
        return rp;
    
public javax.accessibility.AccessibleContextgetAccessibleContext()
Gets the AccessibleContext associated with this JWindow. For JWindows, the AccessibleContext takes the form of an AccessibleJWindow. A new AccessibleJWindow instance is created if necessary.

return
an AccessibleJWindow that serves as the AccessibleContext of this JWindow


                                                         
       
        if (accessibleContext == null) {
            accessibleContext = new AccessibleJWindow();
        }
        return accessibleContext;
    
public java.awt.ContainergetContentPane()
Returns the Container which is the contentPane for this window.

return
the contentPane property
see
#setContentPane
see
RootPaneContainer#getContentPane

 
        return getRootPane().getContentPane(); 
    
public java.awt.ComponentgetGlassPane()
Returns the glassPane Component for this window.

return
the glassPane property
see
#setGlassPane
see
RootPaneContainer#getGlassPane

 
        return getRootPane().getGlassPane(); 
    
public javax.swing.JLayeredPanegetLayeredPane()
Returns the layeredPane object for this window.

return
the layeredPane property
see
#setLayeredPane
see
RootPaneContainer#getLayeredPane

 
        return getRootPane().getLayeredPane(); 
    
public javax.swing.JRootPanegetRootPane()
Returns the rootPane object for this window.

return
the rootPane property for this window
see
#setRootPane
see
RootPaneContainer#getRootPane

 
        return rootPane; 
    
protected booleanisRootPaneCheckingEnabled()
Returns whether calls to add and setLayout are forwarded to the contentPane.

return
true if add and setLayout are fowarded; false otherwise
see
#addImpl
see
#setLayout
see
#setRootPaneCheckingEnabled
see
javax.swing.RootPaneContainer

        return rootPaneCheckingEnabled;
    
protected java.lang.StringparamString()
Returns a string representation of this JWindow. 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 JWindow

        String rootPaneCheckingEnabledString = (rootPaneCheckingEnabled ?
						"true" : "false");

        return super.paramString() +
	",rootPaneCheckingEnabled=" + rootPaneCheckingEnabledString;
    
public voidremove(java.awt.Component comp)
Removes the specified component from the container. If comp is not the rootPane, this will forward the call to the contentPane. This will do nothing if comp is not a child of the JWindow or contentPane.

param
comp the component to be removed
throws
NullPointerException if comp is null
see
#add
see
javax.swing.RootPaneContainer

	if (comp == rootPane) {
	    super.remove(comp);
	} else {
	    getContentPane().remove(comp);
	}
    
public voidsetContentPane(java.awt.Container contentPane)
Sets the contentPane property for this window. This method is called by the constructor.

param
contentPane the new contentPane
exception
IllegalComponentStateException (a runtime exception) if the content pane parameter is null
see
#getContentPane
see
RootPaneContainer#setContentPane
beaninfo
hidden: true description: The client area of the window where child components are normally inserted.

        getRootPane().setContentPane(contentPane);
    
public voidsetGlassPane(java.awt.Component glassPane)
Sets the glassPane property. This method is called by the constructor.

param
glassPane the glassPane object for this window
see
#getGlassPane
see
RootPaneContainer#setGlassPane
beaninfo
hidden: true description: A transparent pane used for menu rendering.

        getRootPane().setGlassPane(glassPane);
    
public voidsetLayeredPane(javax.swing.JLayeredPane layeredPane)
Sets the layeredPane property. This method is called by the constructor.

param
layeredPane the new layeredPane object
exception
IllegalComponentStateException (a runtime exception) if the content pane parameter is null
see
#getLayeredPane
see
RootPaneContainer#setLayeredPane
beaninfo
hidden: true description: The pane which holds the various window layers.

        getRootPane().setLayeredPane(layeredPane);
    
public voidsetLayout(java.awt.LayoutManager manager)
Sets the LayoutManager. Overridden to conditionally forward the call to the contentPane. Refer to {@link javax.swing.RootPaneContainer} for more information.

param
manager the LayoutManager
see
#setRootPaneCheckingEnabled
see
javax.swing.RootPaneContainer

        if(isRootPaneCheckingEnabled()) {
            getContentPane().setLayout(manager);
        }
        else {
            super.setLayout(manager);
        }
    
protected voidsetRootPane(javax.swing.JRootPane root)
Sets the new rootPane object for this window. This method is called by the constructor.

param
root the new rootPane property
see
#getRootPane
beaninfo
hidden: true description: the RootPane object for this window.

        if(rootPane != null) {
            remove(rootPane);
        }
        rootPane = root;
        if(rootPane != null) {
            boolean checkingEnabled = isRootPaneCheckingEnabled();
            try {
                setRootPaneCheckingEnabled(false);
                add(rootPane, BorderLayout.CENTER);
            }
            finally {
                setRootPaneCheckingEnabled(checkingEnabled);
            }
        }
    
protected voidsetRootPaneCheckingEnabled(boolean enabled)
Sets whether calls to add and setLayout are forwarded to the contentPane.

param
enabled true if add and setLayout are forwarded, false if they should operate directly on the JWindow.
see
#addImpl
see
#setLayout
see
#isRootPaneCheckingEnabled
see
javax.swing.RootPaneContainer
beaninfo
hidden: true description: Whether the add and setLayout methods are forwarded

        rootPaneCheckingEnabled = enabled;
    
public voidupdate(java.awt.Graphics g)
Calls paint(g). This method was overridden to prevent an unnecessary call to clear the background.

param
g the Graphics context in which to paint

        paint(g);
    
protected voidwindowInit()
Called by the constructors to init the JWindow properly.

        setLocale( JComponent.getDefaultLocale() );
        setRootPane(createRootPane());
        setRootPaneCheckingEnabled(true);
        sun.awt.SunToolkit.checkAndSetPolicy(this, true);