Window (Java Platform SE 8 )
Skip navigation links Overview Package Class Use Tree Deprecated Index Help Java™ Platform Standard Ed. 8 Prev Class Next Class Frames No Frames All Classes Summary: Nested | Field | Constr | Method Detail: Field | Constr | Method java.awt Class Window java.lang.Object java.awt.Component java.awt.Container java.awt.Window All Implemented Interfaces: ImageObserver , MenuContainer , Serializable , Accessible 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); Note: the location and size of top-level windows (including Window s, Frame s, and Dialog s) are under the control of the desktop's window management system. Calls to setLocation , setSize , and setBounds are requests (not directives) which are forwarded to the window management system.
Every effort will be made to honor such requests. However, in some cases the window management system may ignore such requests, or modify the requested geometry in order to place and size the Window in a way that more closely matches the desktop settings. 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 when the Window is made visible. One or more ComponentEvent s 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 Nested Class Summary Nested Classes Modifier and Type Class Description protected class Window.AccessibleAWTWindow This class implements accessibility support for the Window class. static class Window.Type Enumeration of available window types . 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 inherited from class java.awt. Component accessibleContext , 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 Constructors Constructor Description Window ( Frame owner) Constructs a new, initially invisible window with the specified Frame as its owner. Window ( Window owner) Constructs a new, initially invisible window with the specified Window as its owner. Window ( Window owner, GraphicsConfiguration gc) Constructs a new, initially invisible window with the specified owner Window and a GraphicsConfiguration of a screen device.
Method Summary All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void addNotify () Makes this Window displayable by creating the connection to its native screen resource. void addPropertyChangeListener ( PropertyChangeListener listener) Adds a PropertyChangeListener to the listener list. void addPropertyChangeListener ( String propertyName, PropertyChangeListener listener) Adds a PropertyChangeListener to the listener list for a specific property. 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 addWindowStateListener ( WindowStateListener l) Adds the specified window state listener to receive window events from this window. void applyResourceBundle ( ResourceBundle rb) Deprecated.
As of J2SE 1.4, replaced by Component.applyComponentOrientation . void applyResourceBundle ( String rbName) Deprecated. As of J2SE 1.4, replaced by Component.applyComponentOrientation . void createBufferStrategy (int numBuffers) Creates a new strategy for multi-buffering on this component. void createBufferStrategy (int numBuffers, BufferCapabilities caps) Creates a new strategy for multi-buffering on this component with the required buffer capabilities. void dispose () Releases all of the native screen resources used by this Window , its subcomponents, and all of its owned children.
AccessibleContext getAccessibleContext () Gets the AccessibleContext associated with this Window. Color getBackground () Gets the background color of this window. BufferStrategy getBufferStrategy () Returns the BufferStrategy used by this component. 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 < AWTKeyStroke > getFocusTraversalKeys (int id) Gets a focus traversal key for this Window. List < Image > getIconImages () Returns the sequence of images to be displayed as the icon for this window. InputContext getInputContext () Gets the input context for this window. <T extends EventListener > T[] getListeners ( Class <T> listenerType) Returns an array of all the objects currently registered as Foo Listener s upon this Window .
Locale getLocale () Gets the Locale object that is associated with this window, if the locale has been set. Dialog.ModalExclusionType getModalExclusionType () Returns the modal exclusio
The rest of this page is on the live site.