Use is subject to License Terms. Your use of this web site or any of its content or software indicates your agreement to be bound by these License Terms.

Copyright © 2006 Sun Microsystems, Inc. All rights reserved.

JSR 217 (Maintenance Release)

java.awt
Class Window

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjava.awt.Window
All Implemented Interfaces:
ImageObserver, Serializable
Direct Known Subclasses:
Frame

public class Window
extends Container

A Window object is a top-level window with no borders and no menubar. The default layout for a window is BorderLayout. Note: the location and size of top-level windows (including Windows, Frames, and Dialogs) are under the control of the window management system. Calls to setLocation, setSize, and setBounds are requests (not directives) which are forwarded to the window management system. In some cases the window management system may ignore such requests, or modify the requested geometry in order to place and size the Window appropriately. Due to the asynchronous nature of native event handling, the results returned by getBounds, getLocation, getLocationOnScreen, and getSize might not reflect the actual geometry of the Window on screen until the last request has been processed. During the processing of subsequent requests these values might change accordingly while the window management system fulfills the requests.

An application may set the size and location of an invisible Window arbitrarily, but the window management system may subsequently change its size and/or location if and when the Window is made visible. One or more ComponentEvents will be generated to indicate the new geometry.

Windows are capable of generating the following WindowEvents: WindowOpened, WindowClosed, WindowGainedFocus, WindowLostFocus.

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

Field Summary
 
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
 
Method Summary
 void addWindowFocusListener(WindowFocusListener l)
          Adds the specified window focus listener to receive window events from this window.
 void addWindowListener(WindowListener l)
          Adds the specified window listener to receive window events from this window.
 void dispose()
          Releases all of the native screen resources used by this Window, its subcomponents, and all of its owned children.
 boolean getFocusableWindowState()
          Returns whether this Window can become the focused Window if it meets the other requirements outlined in isFocusableWindow.
 Container getFocusCycleRootAncestor()
          Always returns null because Windows have no ancestors; they represent the top of the Component hierarchy.
 Component getFocusOwner()
          Returns the child Component of this Window that has focus if this Window is focused; returns null otherwise.
 Set getFocusTraversalKeys(int id)
          Gets a focus traversal key for this Window.
 GraphicsConfiguration getGraphicsConfiguration()
          This method returns the GraphicsConfiguration used by this Window.
 InputContext getInputContext()
          Gets the input context for this window.
 Locale getLocale()
          Gets the Locale object that is associated with this window, if the locale has been set.
 Component getMostRecentFocusOwner()
          Returns the child Component of this Window that will receive the focus when this Window is focused.
 Toolkit getToolkit()
          Returns the toolkit of this frame.
 String getWarningString()
          Gets the warning string that is displayed with this window.
 WindowFocusListener[] getWindowFocusListeners()
          Returns an array of all the window focus listeners registered on this window.
 WindowListener[] getWindowListeners()
          Returns an array of all the window listeners registered on this window.
 boolean isActive()
          Returns whether this Window is active.
 boolean isFocusableWindow()
          Returns whether this Window can become the focused Window, that is, whether this Window or any of its subcomponents can become the focus owner.
 boolean isFocusCycleRoot()
          Always returns true because all Windows must be roots of a focus traversal cycle.
 boolean isFocused()
          Returns whether this Window is focused.
 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.
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.
protected  void processWindowFocusEvent(WindowEvent e)
          Processes window focus event occuring on this window by dispatching them to any registered WindowFocusListener objects.
 void removeWindowFocusListener(WindowFocusListener l)
          Removes the specified window focus listener so that it no longer receives window events from this window.
 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 setFocusableWindowState(boolean focusableWindowState)
          Sets whether this Window can become the focused Window if it meets the other requirements outlined in isFocusableWindow.
 void setFocusCycleRoot(boolean focusCycleRoot)
          Does nothing because Windows must always be roots of a focus traversal cycle.
 void show()
          Makes the Window visible.
 void toBack()
          If this Window is visible, sends this Window to the back and may cause it to lose focus or activation if it is the focused or active Window.
 void toFront()
          If this Window is visible, brings this Window to the front and may make it the focused Window.
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, areFocusTraversalKeysSet, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicySet, list, list, paint, paintComponents, paramString, print, printComponents, processContainerEvent, remove, remove, removeAll, removeContainerListener, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, validate, validateTree
 
Methods inherited from class java.awt.Component
addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enableEvents, enableInputMethods, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getCursor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, hasFocus, imageUpdate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isValid, isVisible, list, list, list, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, setBackground, setBounds, setBounds, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

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.

See Also:
Component.isDisplayable(), toFront(), Component.setVisible(boolean)

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 modifications between those actions).

Note: When the last displayable window within the Java virtual machine (VM) is disposed of, the VM may terminate. See AWT Threading Issues for more information.

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

toFront

public void toFront()
If this Window is visible, brings this Window to the front and may make it the focused Window.

Places this Window at the top of the stacking order and shows it in front of any other Windows in this VM. No action will take place if this Window is not visible. Some platforms do not allow Windows which own other Windows to appear on top of those owned Windows. Some platforms may not permit this VM to place its Windows above windows of native applications, or Windows of other VMs. This permission may depend on whether a Window in this VM is already focused. Every attempt will be made to move this Window as high as possible in the stacking order; however, developers should not assume that this method will move this Window above all other windows in every situation.

Because of variations in native windowing systems, no guarantees about changes to the focused and active Windows can be made. Developers must never assume that this Window is the focused or active Window until this Window receives a WINDOW_GAINED_FOCUS or WINDOW_ACTIVATED event. On platforms where the top-most window is the focused window, this method will probably focus this Window, if it is not already focused. On platforms where the stacking order does not typically affect the focused window, this method will probably leave the focused and active Windows unchanged.

If this method causes this Window to be focused, and this Window is a Frame it will also become activated. If this Window is focused, but it is not a Frame then the first Frame that is an owner of this Window will be activated.

See Also:
toBack()

toBack

public void toBack()
If this Window is visible, sends this Window to the back and may cause it to lose focus or activation if it is the focused or active Window.

Places this Window at the bottom of the stacking order and shows it behind any other Windows in this VM. No action will take place is this Window is not visible. Some platforms do not allow Windows which are owned by other Windows to appear below their owners. Every attempt will be made to move this Window as low as possible in the stacking order; however, developers should not assume that this method will move this Window below all other windows in every situation.

Because of variations in native windowing systems, no guarantees about changes to the focused and active Windows can be made. Developers must never assume that this Window is no longer the focused or active Window until this Window receives a WINDOW_LOST_FOCUS or WINDOW_DEACTIVATED event. On platforms where the top-most window is the focused window, this method will probably cause this Window to lose focus. In that case, the next highest, focusable Window in this VM will receive focus. On platforms where the stacking order does not typically affect the focused window, this method will probably leave the focused and active Windows unchanged.

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
Returns:
the input context used by this component; null if no context can be determined
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

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
See Also:
removeWindowListener(java.awt.event.WindowListener)

addWindowFocusListener

public void addWindowFocusListener(WindowFocusListener l)
Adds the specified window focus 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 focus listener
See Also:
removeWindowFocusListener(java.awt.event.WindowFocusListener), getWindowFocusListeners()

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
See Also:
addWindowListener(java.awt.event.WindowListener)

removeWindowFocusListener

public void removeWindowFocusListener(WindowFocusListener l)
Removes the specified window focus 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 focus listener
See Also:
addWindowFocusListener(java.awt.event.WindowFocusListener), getWindowFocusListeners()

getWindowListeners

public WindowListener[] getWindowListeners()
Returns an array of all the window listeners registered on this window.

Returns:
all of this window's WindowListeners or an empty array if no window listeners are currently registered
Since:
1.4
See Also:
addWindowListener(java.awt.event.WindowListener), removeWindowListener(java.awt.event.WindowListener)

getWindowFocusListeners

public WindowFocusListener[] getWindowFocusListeners()
Returns an array of all the window focus listeners registered on this window.

Returns:
all of this window's WindowFocusListeners or an empty array if no window focus listeners are currently registered
Since:
1.4
See Also:
addWindowFocusListener(java.awt.event.WindowFocusListener), removeWindowFocusListener(java.awt.event.WindowFocusListener)

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.

Note that if the event parameter is null the behavior is unspecified and may result in an exception.

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:

Note that if the event parameter is null the behavior is unspecified and may result in an exception.

Parameters:
e - the window event
See Also:
Component.enableEvents(long)

processWindowFocusEvent

protected void processWindowFocusEvent(WindowEvent e)
Processes window focus event occuring on this window by dispatching them to any registered WindowFocusListener objects. NOTE: this method will not be called unless window focus events are enabled for this window. This happens when one of the following occurs:

Note that if the event parameter is null the behavior is unspecified and may result in an exception.

Parameters:
e - the window focus event
See Also:
Component.enableEvents(long)

getFocusOwner

public Component getFocusOwner()
Returns the child Component of this Window that has focus if this Window is focused; returns null otherwise.

Returns:
the child Component with focus, or null if this Window is not focused
See Also:
getMostRecentFocusOwner(), isFocused()

getMostRecentFocusOwner

public Component getMostRecentFocusOwner()
Returns the child Component of this Window that will receive the focus when this Window is focused. If this Window is currently focused, this method returns the same Component as getFocusOwner(). If this Window is not focused, then the child Component that most recently requested focus will be returned. If no child Component has ever requested focus, and this is a focusable Window, then this Window's initial focusable Component is returned. If no child Component has ever requested focus, and this is a non-focusable Window, null is returned.

Returns:
the child Component that will receive focus when this Window is focused
Since:
1.4
See Also:
getFocusOwner(), isFocused(), isFocusableWindow()

isActive

public boolean isActive()
Returns whether this Window is active. Only a Frame may be active. The native windowing system may denote the active Window or its children with special decorations, such as a highlighted title bar. The active Window is always either the focused Window, or the first Frame that is an owner of the focused Window.

Returns:
whether this is the active Window.
Since:
1.4
See Also:
isFocused()

isFocused

public boolean isFocused()
Returns whether this Window is focused. If there exists a focus owner, the focused Window is the Window that is, or contains, that focus owner. If there is no focus owner, then no Window is focused.

If the focused Window is a Frame it is also the active Window. Otherwise, the active Window is the first Frame that is an owner of the focused Window.

Returns:
whether this is the focused Window.
Since:
1.4

getFocusTraversalKeys

public Set getFocusTraversalKeys(int id)
Gets a focus traversal key for this Window. (See setFocusTraversalKeys for a full description of each key.)

If the traversal key has not been explicitly set for this Window, then this Window's parent's traversal key is returned. If the traversal key has not been explicitly set for any of this Window's ancestors, then the current KeyboardFocusManager's default traversal key is returned.

Overrides:
getFocusTraversalKeys in class Container
Parameters:
id - one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
Returns:
the AWTKeyStroke for the specified key
Throws:
IllegalArgumentException - if id is not one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
Since:
1.4
See Also:
Container.setFocusTraversalKeys(int, java.util.Set), KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS

setFocusCycleRoot

public final void setFocusCycleRoot(boolean focusCycleRoot)
Does nothing because Windows must always be roots of a focus traversal cycle. The passed-in value is ignored.

Overrides:
setFocusCycleRoot in class Container
Parameters:
focusCycleRoot - this value is ignored
Since:
1.4
See Also:
isFocusCycleRoot(), Container.setFocusTraversalPolicy(java.awt.FocusTraversalPolicy), Container.getFocusTraversalPolicy()

isFocusCycleRoot

public final boolean isFocusCycleRoot()
Always returns true because all Windows must be roots of a focus traversal cycle.

Overrides:
isFocusCycleRoot in class Container
Returns:
true
Since:
1.4
See Also:
setFocusCycleRoot(boolean), Container.setFocusTraversalPolicy(java.awt.FocusTraversalPolicy), Container.getFocusTraversalPolicy()

getFocusCycleRootAncestor

public final Container getFocusCycleRootAncestor()
Always returns null because Windows have no ancestors; they represent the top of the Component hierarchy.

Overrides:
getFocusCycleRootAncestor in class Component
Returns:
null
Since:
1.4
See Also:
Container.isFocusCycleRoot()

isFocusableWindow

public final boolean isFocusableWindow()
Returns whether this Window can become the focused Window, that is, whether this Window or any of its subcomponents can become the focus owner. For a Frame to be focusable, its focusable Window state must be set to true. For a Window which is not a Frame to be focusable, its focusable Window state must be set to true, its nearest owning Frame must be showing on the screen, and it must contain at least one Component in its focus traversal cycle. If any of these conditions is not met, then neither this Window nor any of its subcomponents can become the focus owner.

Returns:
true if this Window can be the focused Window; false otherwise
Since:
1.4
See Also:
getFocusableWindowState(), setFocusableWindowState(boolean), isShowing(), Component.isFocusable()

getFocusableWindowState

public boolean getFocusableWindowState()
Returns whether this Window can become the focused Window if it meets the other requirements outlined in isFocusableWindow. If this method returns false, then isFocusableWindow will return false as well. If this method returns true, then isFocusableWindow may return true or false depending upon the other requirements which must be met in order for a Window to be focusable.

By default, all Windows have a focusable Window state of true.

Returns:
whether this Window can be the focused Window
Since:
1.4
See Also:
isFocusableWindow(), setFocusableWindowState(boolean), isShowing(), Component.setFocusable(boolean)

setFocusableWindowState

public void setFocusableWindowState(boolean focusableWindowState)
Sets whether this Window can become the focused Window if it meets the other requirements outlined in isFocusableWindow. If this Window's focusable Window state is set to false, then isFocusableWindow will return false. If this Window's focusable Window state is set to true, then isFocusableWindow may return true or false depending upon the other requirements which must be met in order for a Window to be focusable.

Setting a Window's focusability state to false is the standard mechanism for an application to identify to the AWT a Window which will be used as a floating palette or toolbar, and thus should be a non-focusable Window.

Parameters:
focusableWindowState - whether this Window can be the focused Window
Since:
1.4
See Also:
isFocusableWindow(), getFocusableWindowState(), isShowing(), Component.setFocusable(boolean)

isShowing

public boolean isShowing()
Checks if this Window is showing on screen.

Overrides:
isShowing in class Component
Returns:
true if the component is showing, false otherwise
See Also:
Component.setVisible(boolean)

getGraphicsConfiguration

public GraphicsConfiguration getGraphicsConfiguration()
This method returns the GraphicsConfiguration used by this Window.

Overrides:
getGraphicsConfiguration in class Component
Returns:
the GraphicsConfiguration used by this Component or null

JSR 217 (Maintenance Release)

Copyright © 2006 Sun Microsystems, Inc. All rights reserved. Use is subject to License Terms. Your use of this web site or any of its content or software indicates your agreement to be bound by these License Terms.

For more information, please consult the JSR 217 specification.