JavaTM 2 Platform
Std. Ed. v1.3.1

java.awt
Class Window

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Window
All Implemented Interfaces:
Accessible, ImageObserver, MenuContainer, Serializable
Direct Known Subclasses:
BasicToolBarUI.DragWindow, Dialog, Frame, JWindow

public class Window
extends Container
implements Accessible

A Window object is a top-level window with no borders and no menubar. The default layout for a window is BorderLayout.

A window must have either a frame, dialog, or another window defined as its owner when it's constructed.

In a multi-screen environment, you can create a Window on a different screen device by constructing the Window with Window(Window, GraphicsConfiguration). The GraphicsConfiguration object is one of the GraphicsConfiguration objects of the target screen device.

In a virtual device multi-screen environment in which the desktop area could span multiple physical screen devices, the bounds of all configurations are relative to the virtual device coordinate system. The origin of the virtual-coordinate system is at the upper left-hand corner of the primary physical screen. Depending on the location of the primary screen in the virtual device, negative coordinates are possible, as shown in the following figure.

In such an environment, when calling setLocation, you must pass a virtual coordinate to this method. Similarly, calling getLocationOnScreen on a Window returns virtual device coordinates. Call the getBounds method of a GraphicsConfiguration to find its origin in the virtual coordinate system.

The following code sets the location of a Window at (10, 10) relative to the origin of the physical screen of the corresponding GraphicsConfiguration. If the bounds of the GraphicsConfiguration is not taken into account, the Window location would be set at (10, 10) relative to the virtual-coordinate system and would appear on the primary physical screen, which might be different from the physical screen of the specified GraphicsConfiguration.

	Window w = new Window(Window owner, GraphicsConfiguration gc);
	Rectangle bounds = gc.getBounds();
	w.setLocation(10 + bounds.x, 10 + bounds.y);
 

Windows are capable of generating the following window events: WindowOpened, WindowClosed.

Since:
JDK1.0
See Also:
WindowEvent, addWindowListener(java.awt.event.WindowListener), BorderLayout, Serialized Form

Inner Class Summary
protected  class Window.AccessibleAWTWindow
          This class implements accessibility support for the Window class.
 
Inner classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
Component.AccessibleAWTComponent
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Window(Frame owner)
          Constructs a new invisible window with the specified Frame as its owner.
Window(Window owner)
          Constructs a new invisible window with the specified Window as its owner.
Window(Window owner, GraphicsConfiguration gc)
          Constructs a new invisible window with the specified window as its owner and a GraphicsConfiguration of a screen device.
 
Method Summary
 void addNotify()
          Makes this Window displayable by creating the connection to its native screen resource.
 void addWindowListener(WindowListener l)
          Adds the specified window listener to receive window events from this window.
 void applyResourceBundle(ResourceBundle rb)
          Apply the settings in the given ResourceBundle to this Window.
 void applyResourceBundle(String rbName)
          Load the ResourceBundle with the given name using the default locale and apply its settings to this window.
 void dispose()
          Releases all of the native screen resources used by this Window, its subcomponents, and all of its owned children.
protected  void finalize()
          Disposes of the input methods and context, and removes the WeakReference which formerly pointed to this Window from the parent's owned Window list.
 AccessibleContext getAccessibleContext()
          Gets the AccessibleContext associated with this Window.
 Component getFocusOwner()
          Returns the child component of this Window which has focus if and only if this Window is active.
 GraphicsConfiguration getGraphicsConfiguration()
          This method returns the GraphicsConfiguration used by this Window.
 InputContext getInputContext()
          Gets the input context for this window.
 EventListener[] getListeners(Class listenerType)
          Return an array of all the listeners that were added to the Window with addXXXListener(), where XXX is the name of the listenerType argument.
 Locale getLocale()
          Gets the Locale object that is associated with this window, if the locale has been set.
 Window[] getOwnedWindows()
          Return an array containing all the windows this window currently owns.
 Window getOwner()
          Returns the owner of this window.
 Toolkit getToolkit()
          Returns the toolkit of this frame.
 String getWarningString()
          Gets the warning string that is displayed with this window.
 void hide()
          Hide this Window, its subcomponents, and all of its owned children.
 boolean isShowing()
          Checks if this Window is showing on screen.
 void pack()
          Causes this Window to be sized to fit the preferred size and layouts of its subcomponents.
 boolean postEvent(Event e)
          Deprecated. As of JDK version 1.1 replaced by dispatchEvent(AWTEvent).
protected  void processEvent(AWTEvent e)
          Processes events on this window.
protected  void processWindowEvent(WindowEvent e)
          Processes window events occurring on this window by dispatching them to any registered WindowListener objects.
 void removeWindowListener(WindowListener l)
          Removes the specified window listener so that it no longer receives window events from this window.
 void setCursor(Cursor cursor)
          Set the cursor image to a specified cursor.
 void show()
          Makes the Window visible.
 void toBack()
          Sends this window to the back.
 void toFront()
          Brings this window to the front.
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setFont, setLayout, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputMethodRequests, getLocation, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Window

public Window(Frame owner)
Constructs a new invisible window with the specified Frame as its owner.

If there is a security manager, this method first calls the security manager's checkTopLevelWindow method with this as its argument to determine whether or not the window must be displayed with a warning banner.

Parameters:
owner - the Frame to act as owner
Throws:
IllegalArgumentException - if gc is not from a screen device.
IllegalArgumentException - if owner is null
See Also:
SecurityManager.checkTopLevelWindow(java.lang.Object)

Window

public Window(Window owner)
Constructs a new invisible window with the specified Window as its owner.

If there is a security manager, this method first calls the security manager's checkTopLevelWindow method with this as its argument to determine whether or not the window must be displayed with a warning banner.

Parameters:
owner - the Window to act as owner
Throws:
IllegalArgumentException - if owner is null
Since:
1.2
See Also:
SecurityManager.checkTopLevelWindow(java.lang.Object)

Window

public Window(Window owner,
              GraphicsConfiguration gc)
Constructs a new invisible window with the specified window as its owner and a GraphicsConfiguration of a screen device.

If there is a security manager, this method first calls the security manager's checkTopLevelWindow method with this as its argument to determine whether or not the window must be displayed with a warning banner.

Parameters:
owner - the window to act as owner
gc - the GraphicsConfiguration of the target screen device. If gc is null, the system default GraphicsConfiguration is assumed.
Throws:
IllegalArgumentException - if owner is null.
IllegalArgumentException - if gc is not from a screen device.
Since:
1.3
See Also:
SecurityManager.checkTopLevelWindow(java.lang.Object), GraphicsConfiguration.getBounds()
Method Detail

finalize

protected void finalize()
                 throws Throwable
Disposes of the input methods and context, and removes the WeakReference which formerly pointed to this Window from the parent's owned Window list.
Overrides:
finalize in class Object
Following copied from class: java.lang.Object
Throws:
Throwable - the Exception raised by this method

addNotify

public void addNotify()
Makes this Window displayable by creating the connection to its native screen resource. This method is called internally by the toolkit and should not be called directly by programs.
Overrides:
addNotify in class Container
Since:
JDK1.0
See Also:
Component.isDisplayable(), Container.removeNotify()

pack

public void pack()
Causes this Window to be sized to fit the preferred size and layouts of its subcomponents. If the window and/or its owner are not yet displayable, both are made displayable before calculating the preferred size. The Window will be validated after the preferredSize is calculated.
See Also:
Component.isDisplayable()

show

public void show()
Makes the Window visible. If the Window and/or its owner are not yet displayable, both are made displayable. The Window will be validated prior to being made visible. If the Window is already visible, this will bring the Window to the front.
Overrides:
show in class Component
See Also:
Component.isDisplayable(), toFront(), Component.setVisible(boolean)

hide

public void hide()
Hide this Window, its subcomponents, and all of its owned children. The Window and its subcomponents can be made visible again with a call to show.

Overrides:
hide in class Component
See Also:
show(), dispose()

dispose

public void dispose()
Releases all of the native screen resources used by this Window, its subcomponents, and all of its owned children. That is, the resources for these Components will be destroyed, any memory they consume will be returned to the OS, and they will be marked as undisplayable.

The Window and its subcomponents can be made displayable again by rebuilding the native resources with a subsequent call to pack or show. The states of the recreated Window and its subcomponents will be identical to the states of these objects at the point where the Window was disposed (not accounting for additional modifcations between those actions).

See Also:
Component.isDisplayable(), pack(), show()

toFront

public void toFront()
Brings this window to the front. Places this window at the top of the stacking order and shows it in front of any other windows.
See Also:
toBack()

toBack

public void toBack()
Sends this window to the back. Places this window at the bottom of the stacking order and makes the corresponding adjustment to other visible windows.
See Also:
toFront()

getToolkit

public Toolkit getToolkit()
Returns the toolkit of this frame.
Overrides:
getToolkit in class Component
Returns:
the toolkit of this window.
See Also:
Toolkit, Toolkit.getDefaultToolkit(), Component.getToolkit()

getWarningString

public final String getWarningString()
Gets the warning string that is displayed with this window. If this window is insecure, the warning string is displayed somewhere in the visible area of the window. A window is insecure if there is a security manager, and the security manager's checkTopLevelWindow method returns false when this window is passed to it as an argument.

If the window is secure, then getWarningString returns null. If the window is insecure, this method checks for the system property awt.appletWarning and returns the string value of that property.

Returns:
the warning string for this window.
See Also:
SecurityManager.checkTopLevelWindow(java.lang.Object)

getLocale

public Locale getLocale()
Gets the Locale object that is associated with this window, if the locale has been set. If no locale has been set, then the default locale is returned.
Overrides:
getLocale in class Component
Returns:
the locale that is set for this window.
Since:
JDK1.1
See Also:
Locale

getInputContext

public InputContext getInputContext()
Gets the input context for this window. A window always has an input context, which is shared by subcomponents unless they create and set their own.
Overrides:
getInputContext in class Component
Since:
1.2
See Also:
Component.getInputContext()

setCursor

public void setCursor(Cursor cursor)
Set the cursor image to a specified cursor.
Overrides:
setCursor in class Component
Parameters:
cursor - One of the constants defined by the Cursor class. If this parameter is null then the cursor for this window will be set to the type Cursor.DEFAULT_CURSOR.
Since:
JDK1.1
See Also:
Component.getCursor(), Cursor

getOwner

public Window getOwner()
Returns the owner of this window.

getOwnedWindows

public Window[] getOwnedWindows()
Return an array containing all the windows this window currently owns.
Since:
1.2

addWindowListener

public void addWindowListener(WindowListener l)
Adds the specified window listener to receive window events from this window. If l is null, no exception is thrown and no action is performed.
Parameters:
l - the window listener

removeWindowListener

public void removeWindowListener(WindowListener l)
Removes the specified window listener so that it no longer receives window events from this window. If l is null, no exception is thrown and no action is performed.
Parameters:
l - the window listener

getListeners

public EventListener[] getListeners(Class listenerType)
Return an array of all the listeners that were added to the Window with addXXXListener(), where XXX is the name of the listenerType argument. For example, to get all of the WindowListener(s) for the given Window w, one would write:
 WindowListener[] wls = (WindowListener[])(w.getListeners(WindowListener.class))
 
If no such listener list exists, then an empty array is returned.
Overrides:
getListeners in class Container
Parameters:
listenerType - Type of listeners requested
Returns:
all of the listeners of the specified type supported by this text field
Since:
1.3

processEvent

protected void processEvent(AWTEvent e)
Processes events on this window. If the event is an WindowEvent, it invokes the processWindowEvent method, else it invokes its superclass's processEvent.
Overrides:
processEvent in class Container
Parameters:
e - the event

processWindowEvent

protected void processWindowEvent(WindowEvent e)
Processes window events occurring on this window by dispatching them to any registered WindowListener objects. NOTE: This method will not be called unless window events are enabled for this component; this happens when one of the following occurs: a) A WindowListener object is registered via addWindowListener() b) Window events are enabled via enableEvents()
Parameters:
e - the window event
See Also:
Component.enableEvents(long)

getFocusOwner

public Component getFocusOwner()
Returns the child component of this Window which has focus if and only if this Window is active.
Returns:
the component with focus, or null if no children have focus assigned to them.

postEvent

public boolean postEvent(Event e)
Deprecated. As of JDK version 1.1 replaced by dispatchEvent(AWTEvent).

Overrides:
postEvent in class Component

isShowing

public boolean isShowing()
Checks if this Window is showing on screen.
Overrides:
isShowing in class Component
See Also:
Component.setVisible(boolean)

applyResourceBundle

public void applyResourceBundle(ResourceBundle rb)
Apply the settings in the given ResourceBundle to this Window. Currently, this applies the ResourceBundle's ComponentOrientation to this Window and all components contained within it.
Since:
1.2
See Also:
ComponentOrientation

applyResourceBundle

public void applyResourceBundle(String rbName)
Load the ResourceBundle with the given name using the default locale and apply its settings to this window. Currently, this applies the ResourceBundle's ComponentOrientation to this Window and all components contained within it.
Since:
1.2
See Also:
ComponentOrientation

getAccessibleContext

public AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this Window. For windows, the AccessibleContext takes the form of an AccessibleAWTWindow. A new AccessibleAWTWindow instance is created if necessary.
Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in class Component
Returns:
an AccessibleAWTWindow that serves as the AccessibleContext of this Window

getGraphicsConfiguration

public GraphicsConfiguration getGraphicsConfiguration()
This method returns the GraphicsConfiguration used by this Window.
Overrides:
getGraphicsConfiguration in class Component
Following copied from class: java.awt.Component
Returns:
the GraphicsConfiguration used by this Component or null

JavaTM 2 Platform
Std. Ed. v1.3.1

Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.

Java, Java 2D, and JDBC are trademarks or registered trademarks of Oracle and/or its affiliates, in the US and other countries.
Copyright © 1995, 2010 Oracle and/or its affiliates. All rights reserved.