Class Window
- All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible
- Direct Known Subclasses:
BasicToolBarUI.DragWindow, Dialog, Frame, JWindow
public class Window extends Container implements Accessible
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 Windows, Frames, and Dialogs) 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.
Visual effects such as halos, shadows, motion effects and animations may be applied to the window by the desktop window management system. These are outside the knowledge and control of the AWT and so for the purposes of this specification are not considered part of the top-level window.
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 ComponentEvents will be generated to indicate the new geometry.
Windows are capable of generating the following WindowEvents: WindowOpened, WindowClosed, WindowGainedFocus, WindowLostFocus.
- Since:
- 1.0
- See Also:
Nested Class Summary
| Modifier and Type | Class | Description |
|---|---|---|
protected class |
Window.AccessibleAWTWindow |
This class implements accessibility support for the Window class. |
static enum |
Window.Type |
Enumeration of available window types. |
Nested classes/interfaces declared in class Container
Container.AccessibleAWTContainer | Modifier and Type | Class | Description |
|---|---|---|
protected class |
Container.AccessibleAWTContainer |
Inner class of Container used to provide default support for accessibility. |
Nested classes/interfaces declared in class Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy | Modifier and Type | Class | Description |
|---|---|---|
protected class |
Component.AccessibleAWTComponent |
Inner class of Component used to provide default support for accessibility. |
static enum |
Component.BaselineResizeBehavior |
Enumeration of the common ways the baseline of a component can change as the size changes. |
protected class |
Component.BltBufferStrategy |
Inner class for blitting offscreen surfaces to a component. |
protected class |
Component.FlipBufferStrategy |
Inner class for flipping buffers on a component. |
Field Summary
Fields declared in class Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT | Modifier and Type | Field | Description |
|---|---|---|
protected AccessibleContext |
accessibleContext |
The AccessibleContext associated with this Component. |
static final float |
BOTTOM_ALIGNMENT |
Ease-of-use constant for getAlignmentY. |
static final float |
CENTER_ALIGNMENT |
Ease-of-use constant for getAlignmentY and getAlignmentX. |
static final float |
LEFT_ALIGNMENT |
Ease-of-use constant for getAlignmentX. |
static final float |
RIGHT_ALIGNMENT |
Ease-of-use constant for getAlignmentX. |
static final float |
TOP_ALIGNMENT |
Ease-of-use constant for getAlignmentY(). |
Fields declared in interface ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH | Modifier and Type | Field | Description |
|---|---|---|
static final int |
ABORT |
This flag in the infoflags argument to imageUpdate indicates that an image which was being tracked asynchronously was aborted before production was complete. |
static final int |
ALLBITS |
This flag in the infoflags argument to imageUpdate indicates that a static image which was previously drawn is now complete and can be drawn again in its final form. |
static final int |
ERROR |
This flag in the infoflags argument to imageUpdate indicates that an image which was being tracked asynchronously has encountered an error. |
static final int |
FRAMEBITS |
This flag in the infoflags argument to imageUpdate indicates that another complete frame of a multi-frame image which was previously drawn is now available to be drawn again. |
static final int |
HEIGHT |
This flag in the infoflags argument to imageUpdate indicates that the height of the base image is now available and can be taken from the height argument to the imageUpdate callback method. |
static final int |
PROPERTIES |
This flag in the infoflags argument to imageUpdate indicates that the properties of the image are now available. |
static final int |
SOMEBITS |
This flag in the infoflags argument to imageUpdate indicates that more pixels needed for drawing a scaled variation of the image are available. |
static final int |
WIDTH |
This flag in the infoflags argument to imageUpdate indicates that the width of the base image is now available and can be taken from the width argument to the imageUpdate callback method. |
Constructor Summary
| Constructor | Description |
|---|---|
Window |
Constructs a new, initially invisible window with the specified Frame as its owner. |
Window |
Constructs a new, initially invisible window with the specified Window as its owner. |
Window |
Constructs a new, initially invisible window with the specified owner Window and a GraphicsConfiguration of a screen device. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
void |
addNotify() |
Makes this Window displayable by creating the connection to its native screen resource. |
void |
addPropertyChangeListener |
Adds a PropertyChangeListener to the listener list. |
void |
addPropertyChangeListener |
Adds a PropertyChangeListener to the listener list for a specific property. |
void |
addWindowFocusListener |
Adds the specified window focus listener to receive window events from this window. |
void |
addWindowListener |
Adds the specified window listener to receive window events from this window. |
void |
addWindowStateListener |
Adds the specified window state listener to receive window events from this window. |
void |
applyResourceBundle |
Deprecated. |
void |
applyResourceBundle |
Deprecated. As of J2SE 1.4, replaced by Component.applyComponentOrientation. |
void |
createBufferStrategy |
Creates a new strategy for multi-buffering on this component. |
void |
createBufferStrategy |
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. |
final 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 |
Gets a focus traversal key for this Window. |
List |
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> |
getListeners |
Returns an array of all the objects currently registered as FooListeners 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 exclusion type of this window. |
Component |
getMostRecentFocusOwner() |
Returns the child Component of this Window that will receive the focus when this Window is focused. |
float |
getOpacity() |
Returns the opacity of the window. |
Window[] |
getOwnedWindows() |
Return an array containing all the windows this window currently owns. |
Window |
getOwner() |
Returns the owner of this window. |
static Window[] |
getOwnerlessWindows() |
Returns an array of all Windows created by this application that have no owner. |
Shape |
getShape() |
Returns the shape of the window. |
Toolkit |
getToolkit() |
Returns the toolkit of this frame. |
Window.Type |
getType() |
Returns the type of the window. |
final String |
getWarningString() |
Deprecated, for removal: This API element is subject to removal in a future version. since JDK 24 |
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. |
static Window[] |
getWindows() |
Returns an array of all Windows, both owned and ownerless, created by this application. |
WindowStateListener[] |
getWindowStateListeners() |
Returns an array of all the window state listeners registered on this window. |
void |
hide() |
Deprecated. As of JDK version 1.5, replaced by setVisible(boolean). |
boolean |
isActive() |
Returns whether this Window is active. |
final boolean |
isAlwaysOnTop() |
Returns whether this window is an always-on-top window. |
boolean |
isAlwaysOnTopSupported() |
Returns whether the always-on-top mode is supported for this window. |
boolean |
isAutoRequestFocus() |
Returns whether this window should receive focus on subsequently being shown (with a call to setVisible(true)), or being moved to the front (with a call to toFront()). |
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. |
final 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 |
isLocationByPlatform() |
Returns true if this Window will appear at the default location for the native windowing system the next time this Window is made visible. |
boolean |
isOpaque() |
Indicates if the window is currently opaque. |
boolean |
isShowing() |
Checks if this Window is showing on screen. |
boolean |
isValidateRoot() |
Indicates if this container is a validate root. |
void |
pack() |
Causes this Window to be sized to fit the preferred size and layouts of its subcomponents. |
void |
paint |
Paints the container. |
boolean |
postEvent |
Deprecated. As of JDK version 1.1 replaced by dispatchEvent(AWTEvent). |
protected void |
processEvent |
Processes events on this window. |
protected void |
processWindowEvent |
Processes window events occurring on this window by dispatching them to any registered WindowListener objects. |
protected void |
processWindowFocusEvent |
Processes window focus event occurring on this window by dispatching them to any registered WindowFocusListener objects. |
protected void |
processWindowStateEvent |
Processes window state event occurring on this window by dispatching them to any registered WindowStateListener objects. |
void |
removeWindowFocusListener |
Removes the specified window focus listener so that it no longer receives window events from this window. |
void |
removeWindowListener |
Removes the specified window listener so that it no longer receives window events from this window. |
void |
removeWindowStateListener |
Removes the specified window state listener so that it no longer receives window events from this window. |
void |
reshape |
Deprecated. As of JDK version 1.1, replaced by setBounds(int, int, int, int). |
final void |
setAlwaysOnTop |
Sets whether this window should always be above other windows. |
void |
setAutoRequestFocus |
Sets whether this window should receive focus on subsequently being shown (with a call to setVisible(true)), or being moved to the front (with a call to toFront()). |
void |
setBackground |
Sets the background color of this window. |
void |
setBounds |
Moves and resizes this component. |
void |
setBounds |
Moves and resizes this component to conform to the new bounding rectangle r. |
void |
setCursor |
Set the cursor image to a specified cursor. |
void |
setFocusableWindowState |
Sets whether this Window can become the focused Window if it meets the other requirements outlined in isFocusableWindow. |
final void |
setFocusCycleRoot |
Does nothing because Windows must always be roots of a focus traversal cycle. |
void |
setIconImage |
Sets the image to be displayed as the icon for this window. |
void |
setIconImages |
Sets the sequence of images to be displayed as the icon for this window. |
void |
setLocation |
Moves this component to a new location. |
void |
setLocation |
Moves this component to a new location. |
void |
setLocationByPlatform |
Sets whether this Window should appear at the default location for the native windowing system or at the current location (returned by getLocation) the next time the Window is made visible. |
void |
setLocationRelativeTo |
Sets the location of the window relative to the specified component according to the following scenarios. |
void |
setMinimumSize |
Sets the minimum size of this window to a constant value. |
void |
setModalExclusionType |
Specifies the modal exclusion type for this window. |
void |
setOpacity |
Sets the opacity of the window. |
void |
setShape |
Sets the shape of the window. |
void |
setSize |
Resizes this component so that it has width width and height height. |
void |
setSize |
Resizes this component so that it has width d.width and height d.height. |
void |
setType |
Sets the type of the window. |
void |
setVisible |
Shows or hides this Window depending on the value of parameter b. |
void |
show() |
Deprecated. As of JDK version 1.5, replaced by setVisible(boolean). |
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 declared in class Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusDownCycle, update, validate, validateTree | Modifier and Type | Method | Description |
|---|---|---|
Component |
add |
Appends the specified component to the end of this container. |
Component |
add |
Adds the specified component to this container at the given position. |
void |
add |
Adds the specified component to the end of this container. |
void |
add |
Adds the specified component to this container with the specified constraints at the specified index. |
Component |
add |
Adds the specified component to this container. |
void |
addContainerListener |
Adds the specified container listener to receive container events from this container. |
protected void |
addImpl |
Adds the specified component to this container at the specified index. |
void |
applyComponentOrientation |
Sets the ComponentOrientation property of this container and all components contained within it. |
boolean |
areFocusTraversalKeysSet |
Returns whether the Set of focus traversal keys for the given focus traversal operation has been explicitly defined for this Container. |
int |
countComponents() |
Deprecated. As of JDK version 1.1, replaced by getComponentCount(). |
void |
deliverEvent |
Deprecated. As of JDK version 1.1, replaced by dispatchEvent(AWTEvent e)
|
void |
doLayout() |
Causes this container to lay out its components. |
Component |
findComponentAt |
Locates the visible child component that contains the specified position. |
Component |
findComponentAt |
Locates the visible child component that contains the specified point. |
float |
getAlignmentX() |
Returns the alignment along the x axis. |
float |
getAlignmentY() |
Returns the alignment along the y axis. |
Component |
getComponent |
Gets the nth component in this container. |
Component |
getComponentAt |
Locates the component that contains the x,y position. |
Component |
getComponentAt |
Gets the component that contains the specified point. |
int |
getComponentCount() |
Gets the number of components in this panel. |
Component[] |
getComponents() |
Gets all the components in this container. |
int |
getComponentZOrder |
Returns the z-order index of the component inside the container. |
ContainerListener[] |
getContainerListeners() |
Returns an array of all the container listeners registered on this container. |
FocusTraversalPolicy |
getFocusTraversalPolicy() |
Returns the focus traversal policy that will manage keyboard traversal of this Container's children, or null if this Container is not a focus cycle root. |
Insets |
getInsets() |
Determines the insets of this container, which indicate the size of the container's border. |
LayoutManager |
getLayout() |
Gets the layout manager for this container. |
Dimension |
getMaximumSize() |
Returns the maximum size of this container. |
Dimension |
getMinimumSize() |
Returns the minimum size of this container. |
Point |
getMousePosition |
Returns the position of the mouse pointer in this Container's coordinate space if the Container is under the mouse pointer, otherwise returns null. |
Dimension |
getPreferredSize() |
Returns the preferred size of this container. |
Insets |
insets() |
Deprecated. As of JDK version 1.1, replaced by getInsets(). |
void |
invalidate() |
Invalidates the container. |
boolean |
isAncestorOf |
Checks if the component is contained in the component hierarchy of this container. |
boolean |
isFocusCycleRoot |
Returns whether the specified Container is the focus cycle root of this Container's focus traversal cycle. |
final boolean |
isFocusTraversalPolicyProvider() |
Returns whether this container provides focus traversal policy. |
boolean |
isFocusTraversalPolicySet() |
Returns whether the focus traversal policy has been explicitly set for this Container. |
void |
layout() |
Deprecated. As of JDK version 1.1, replaced by doLayout(). |
void |
list |
Prints a listing of this container to the specified output stream. |
void |
list |
Prints out a list, starting at the specified indentation, to the specified print writer. |
Component |
locate |
Deprecated. As of JDK version 1.1, replaced by getComponentAt(int, int). |
Dimension |
minimumSize() |
Deprecated. As of JDK version 1.1, replaced by getMinimumSize(). |
void |
paintComponents |
Paints each of the components in this container. |
protected String |
paramString() |
Returns a string representing the state of this Container. |
Dimension |
preferredSize() |
Deprecated. As of JDK version 1.1, replaced by getPreferredSize(). |
void |
print |
Prints the container. |
void |
printComponents |
Prints each of the components in this container. |
protected void |
processContainerEvent |
Processes container events occurring on this container by dispatching them to any registered ContainerListener objects. |
void |
remove |
Removes the component, specified by index, from this container. |
void |
remove |
Removes the specified component from this container. |
void |
removeAll() |
Removes all the components from this container. |
void |
removeContainerListener |
Removes the specified container listener so it no longer receives container events from this container. |
void |
removeNotify() |
Makes this Container undisplayable by removing its connection to its native screen resource. |
void |
setComponentZOrder |
Moves the specified component to the specified z-order index in the container. |
void |
setFocusTraversalKeys |
Sets the focus traversal keys for a given traversal operation for this Container. |
void |
setFocusTraversalPolicy |
Sets the focus traversal policy that will manage keyboard traversal of this Container's children, if this Container is a focus cycle root. |
final void |
setFocusTraversalPolicyProvider |
Sets whether this container will be used to provide focus traversal policy. |
void |
setFont |
Sets the font of this container. |
void |
setLayout |
Sets the layout manager for this container. |
void |
transferFocusDownCycle() |
Transfers the focus down one focus traversal cycle. |
void |
update |
Updates the container. |
void |
validate() |
Validates this container and all of its subcomponents. |
protected void |
validateTree() |
Recursively descends the container tree and recomputes the layout for any subtrees marked as needing it (those marked as invalid). |
Methods declared in class Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, 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, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, resize, resize, revalidate, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setMaximumSize, setMixingCutoutShape, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle | Modifier and Type | Method | Description |
|---|---|---|
boolean |
action |
Deprecated. As of JDK version 1.1, should register this component as ActionListener on component which fires action events. |
void |
add |
Adds the specified popup menu to the component. |
void |
addComponentListener |
Adds the specified component listener to receive component events from this component. |
void |
addFocusListener |
Adds the specified focus listener to receive focus events from this component when this component gains input focus. |
void |
addHierarchyBoundsListener |
Adds the specified hierarchy bounds listener to receive hierarchy bounds events from this component when the hierarchy to which this container belongs changes. |
void |
addHierarchyListener |
Adds the specified hierarchy listener to receive hierarchy changed events from this component when the hierarchy to which this container belongs changes. |
void |
addInputMethodListener |
Adds the specified input method listener to receive input method events from this component. |
void |
addKeyListener |
Adds the specified key listener to receive key events from this component. |
void |
addMouseListener |
Adds the specified mouse listener to receive mouse events from this component. |
void |
addMouseMotionListener |
Adds the specified mouse motion listener to receive mouse motion events from this component. |
void |
addMouseWheelListener |
Adds the specified mouse wheel listener to receive mouse wheel events from this component. |
Rectangle |
bounds() |
Deprecated. As of JDK version 1.1, replaced by getBounds(). |
int |
checkImage |
Returns the status of the construction of a screen representation of the specified image. |
int |
checkImage |
Returns the status of the construction of a screen representation of the specified image. |
protected AWTEvent |
coalesceEvents |
Potentially coalesce an event being posted with an existing event. |
boolean |
contains |
Checks whether this component "contains" the specified point, where x and y are defined to be relative to the coordinate system of this component. |
boolean |
contains |
Checks whether this component "contains" the specified point, where the point's x and y coordinates are defined to be relative to the coordinate system of this component. |
Image |
createImage |
Creates an off-screen drawable image to be used for double buffering. |
Image |
createImage |
Creates an image from the specified image producer. |
VolatileImage |
createVolatileImage |
Creates a volatile off-screen drawable image to be used for double buffering. |
VolatileImage |
createVolatileImage |
Creates a volatile off-screen drawable image, with the given capabilities. |
void |
disable() |
Deprecated. As of JDK version 1.1, replaced by setEnabled(boolean). |
protected final void |
disableEvents |
Disables the events defined by the specified event mask parameter from being delivered to this component. |
final void |
dispatchEvent |
Dispatches an event to this component or one of its sub components. |
void |
enable() |
Deprecated. As of JDK version 1.1, replaced by setEnabled(boolean). |
void |
enable |
Deprecated. As of JDK version 1.1, replaced by setEnabled(boolean). |
protected final void |
enableEvents |
Enables the events defined by the specified event mask parameter to be delivered to this component. |
void |
enableInputMethods |
Enables or disables input method support for this component. |
protected void |
firePropertyChange |
Support for reporting bound property changes for boolean properties. |
void |
firePropertyChange |
Reports a bound property change. |
void |
firePropertyChange |
Reports a bound property change. |
void |
firePropertyChange |
Reports a bound property change. |
void |
firePropertyChange |
Reports a bound property change. |
protected void |
firePropertyChange |
Support for reporting bound property changes for integer properties. |
void |
firePropertyChange |
Reports a bound property change. |
void |
firePropertyChange |
Reports a bound property change. |
protected void |
firePropertyChange |
Support for reporting bound property changes for Object properties. |
int |
getBaseline |
Returns the baseline. |
Component.BaselineResizeBehavior |
getBaselineResizeBehavior() |
Returns an enum indicating how the baseline of the component changes as the size changes. |
Rectangle |
getBounds() |
Gets the bounds of this component in the form of a Rectangle object. |
Rectangle |
getBounds |
Stores the bounds of this component into "return value" rv and return rv. |
ColorModel |
getColorModel() |
Gets the instance of ColorModel used to display the component on the output device. |
ComponentListener[] |
getComponentListeners() |
Returns an array of all the component listeners registered on this component. |
ComponentOrientation |
getComponentOrientation() |
Retrieves the language-sensitive orientation that is to be used to order the elements or text within this component. |
Cursor |
getCursor() |
Gets the cursor set in the component. |
DropTarget |
getDropTarget() |
Gets the DropTarget associated with this Component. |
FocusListener[] |
getFocusListeners() |
Returns an array of all the focus listeners registered on this component. |
boolean |
getFocusTraversalKeysEnabled() |
Returns whether focus traversal keys are enabled for this Component. |
Font |
getFont() |
Gets the font of this component. |
FontMetrics |
getFontMetrics |
Gets the font metrics for the specified font. |
Color |
getForeground() |
Gets the foreground color of this component. |
Graphics |
getGraphics() |
Creates a graphics context for this component. |
GraphicsConfiguration |
getGraphicsConfiguration() |
Gets the GraphicsConfiguration associated with this Component. |
int |
getHeight() |
Returns the current height of this component. |
HierarchyBoundsListener[] |
getHierarchyBoundsListeners() |
Returns an array of all the hierarchy bounds listeners registered on this component. |
HierarchyListener[] |
getHierarchyListeners() |
Returns an array of all the hierarchy listeners registered on this component. |
boolean |
getIgnoreRepaint() |
Returns whether or not paint messages received from the operating system should be ignored. |
InputMethodListener[] |
getInputMethodListeners() |
Returns an array of all the input method listeners registered on this component. |
InputMethodRequests |
getInputMethodRequests() |
Gets the input method request handler which supports requests from input methods for this component. |
KeyListener[] |
getKeyListeners() |
Returns an array of all the key listeners registered on this component. |
Point |
getLocation() |
Gets the location of this component in the form of a point specifying the component's top-left corner. |
Point |
getLocation |
Stores the x,y origin of this component into "return value" rv and return rv. |
Point |
getLocationOnScreen() |
Gets the location of this component in the form of a point specifying the component's top-left corner in the screen's coordinate space. |
MouseListener[] |
getMouseListeners() |
Returns an array of all the mouse listeners registered on this component. |
MouseMotionListener[] |
getMouseMotionListeners() |
Returns an array of all the mouse motion listeners registered on this component. |
Point |
getMousePosition() |
Returns the position of the mouse pointer in this Component's coordinate space if the Component is directly under the mouse pointer, otherwise returns null. |
MouseWheelListener[] |
getMouseWheelListeners() |
Returns an array of all the mouse wheel listeners registered on this component. |
String |
getName() |
Gets the name of the component. |
Container |
getParent() |
Gets the parent of this component. |
PropertyChangeListener[] |
getPropertyChangeListeners() |
Returns an array of all the property change listeners registered on this component. |
PropertyChangeListener[] |
getPropertyChangeListeners |
Returns an array of all the listeners which have been associated with the named property. |
Dimension |
getSize() |
Returns the size of this component in the form of a Dimension object. |
Dimension |
getSize |
Stores the width/height of this component into "return value" rv and return rv. |
final Object |
getTreeLock() |
Gets this component's locking object (the object that owns the thread synchronization monitor) for AWT component-tree and layout operations. |
int |
getWidth() |
Returns the current width of this component. |
int |
getX() |
Returns the current x coordinate of the components origin. |
int |
getY() |
Returns the current y coordinate of the components origin. |
boolean |
gotFocus |
Deprecated. As of JDK version 1.1, replaced by processFocusEvent(FocusEvent). |
boolean |
handleEvent |
Deprecated. As of JDK version 1.1 replaced by processEvent(AWTEvent). |
boolean |
hasFocus() |
Returns true if this Component is the focus owner. |
boolean |
imageUpdate |
Repaints the component when the image has changed. |
boolean |
inside |
Deprecated. As of JDK version 1.1, replaced by contains(int, int). |
boolean |
isBackgroundSet() |
Returns whether the background color has been explicitly set for this Component. |
boolean |
isCursorSet() |
Returns whether the cursor has been explicitly set for this Component. |
boolean |
isDisplayable() |
Determines whether this component is displayable. |
boolean |
isDoubleBuffered() |
Returns true if this component is painted to an offscreen image ("buffer") that's copied to the screen later. |
boolean |
isEnabled() |
Determines whether this component is enabled. |
boolean |
isFocusable() |
Returns whether this Component can be focused. |
boolean |
isFocusOwner() |
Returns true if this Component is the focus owner. |
boolean |
isFocusTraversable() |
Deprecated. As of 1.4, replaced by isFocusable(). |
boolean |
isFontSet() |
Returns whether the font has been explicitly set for this Component. |
boolean |
isForegroundSet() |
Returns whether the foreground color has been explicitly set for this Component. |
boolean |
isLightweight() |
A lightweight component doesn't have a native toolkit peer. |
boolean |
isMaximumSizeSet() |
Returns true if the maximum size has been set to a non- null value otherwise returns false. |
boolean |
isMinimumSizeSet() |
Returns whether or not setMinimumSize has been invoked with a non-null value. |
boolean |
isPreferredSizeSet() |
Returns true if the preferred size has been set to a non- null value otherwise returns false. |
boolean |
isValid() |
Determines whether this component is valid. |
boolean |
isVisible() |
Determines whether this component should be visible when its parent is visible. |
boolean |
keyDown |
Deprecated. As of JDK version 1.1, replaced by processKeyEvent(KeyEvent). |
boolean |
keyUp |
Deprecated. As of JDK version 1.1, replaced by processKeyEvent(KeyEvent). |
void |
list() |
Prints a listing of this component to the standard system output stream System.out. |
void |
list |
Prints a listing of this component to the specified output stream. |
void |
list |
Prints a listing to the specified print writer. |
Point |
location() |
Deprecated. As of JDK version 1.1, replaced by getLocation(). |
boolean |
lostFocus |
Deprecated. As of JDK version 1.1, replaced by processFocusEvent(FocusEvent). |
boolean |
mouseDown |
Deprecated. As of JDK version 1.1, replaced by processMouseEvent(MouseEvent). |
boolean |
mouseDrag |
Deprecated. As of JDK version 1.1, replaced by processMouseMotionEvent(MouseEvent). |
boolean |
mouseEnter |
Deprecated. As of JDK version 1.1, replaced by processMouseEvent(MouseEvent). |
boolean |
mouseExit |
Deprecated. As of JDK version 1.1, replaced by processMouseEvent(MouseEvent). |
boolean |
mouseMove |
Deprecated. As of JDK version 1.1, replaced by processMouseMotionEvent(MouseEvent). |
boolean |
mouseUp |
Deprecated. As of JDK version 1.1, replaced by processMouseEvent(MouseEvent). |
void |
move |
Deprecated. As of JDK version 1.1, replaced by setLocation(int, int). |
void |
nextFocus() |
Deprecated. As of JDK version 1.1, replaced by transferFocus(). |
void |
paintAll |
Paints this component and all of its subcomponents. |
boolean |
prepareImage |
Prepares an image for rendering on this component at the specified width and height. |
boolean |
prepareImage |
Prepares an image for rendering on this component. |
void |
printAll |
Prints this component and all of its subcomponents. |
protected void |
processComponentEvent |
Processes component events occurring on this component by dispatching them to any registered ComponentListener objects. |
protected void |
processFocusEvent |
Processes focus events occurring on this component by dispatching them to any registered FocusListener objects. |
protected void |
processHierarchyBoundsEvent |
Processes hierarchy bounds events occurring on this component by dispatching them to any registered HierarchyBoundsListener objects. |
protected void |
processHierarchyEvent |
Processes hierarchy events occurring on this component by dispatching them to any registered HierarchyListener objects. |
protected void |
processInputMethodEvent |
Processes input method events occurring on this component by dispatching them to any registered InputMethodListener objects. |
protected void |
processKeyEvent |
Processes key events occurring on this component by dispatching them to any registered KeyListener objects. |
protected void |
processMouseEvent |
Processes mouse events occurring on this component by dispatching them to any registered MouseListener objects. |
protected void |
processMouseMotionEvent |
Processes mouse motion events occurring on this component by dispatching them to any registered MouseMotionListener objects. |
protected void |
processMouseWheelEvent |
Processes mouse wheel events occurring on this component by dispatching them to any registered MouseWheelListener objects. |
void |
remove |
Removes the specified popup menu from the component. |
void |
removeComponentListener |
Removes the specified component listener so that it no longer receives component events from this component. |
void |
removeFocusListener |
Removes the specified focus listener so that it no longer receives focus events from this component. |
void |
removeHierarchyBoundsListener |
Removes the specified hierarchy bounds listener so that it no longer receives hierarchy bounds events from this component. |
void |
removeHierarchyListener |
Removes the specified hierarchy listener so that it no longer receives hierarchy changed events from this component. |
void |
removeInputMethodListener |
Removes the specified input method listener so that it no longer receives input method events from this component. |
void |
removeKeyListener |
Removes the specified key listener so that it no longer receives key events from this component. |
void |
removeMouseListener |
Removes the specified mouse listener so that it no longer receives mouse events from this component. |
void |
removeMouseMotionListener |
Removes the specified mouse motion listener so that it no longer receives mouse motion events from this component. |
void |
removeMouseWheelListener |
Removes the specified mouse wheel listener so that it no longer receives mouse wheel events from this component. |
void |
removePropertyChangeListener |
Removes a PropertyChangeListener from the listener list. |
void |
removePropertyChangeListener |
Removes a PropertyChangeListener from the listener list for a specific property. |
void |
repaint() |
Repaints this component. |
void |
repaint |
Repaints the specified rectangle of this component. |
void |
repaint |
Repaints the component. |
void |
repaint |
Repaints the specified rectangle of this component within tm milliseconds. |
void |
requestFocus() |
Requests that this Component get the input focus, and that this Component's top-level ancestor become the focused Window. |
protected boolean |
requestFocus |
Requests that this Component get the input focus, and that this Component's top-level ancestor become the focused Window. |
protected boolean |
requestFocus |
Requests by the reason of cause that this Component get the input focus, and that this Component's top-level ancestor become the focused Window. |
void |
requestFocus |
Requests by the reason of cause that this Component get the input focus, and that this Component's top-level ancestor become the focused Window. |
boolean |
requestFocusInWindow() |
Requests that this Component get the input focus, if this Component's top-level ancestor is already the focused Window. |
protected boolean |
requestFocusInWindow |
Requests that this Component get the input focus, if this Component's top-level ancestor is already the focused Window. |
boolean |
requestFocusInWindow |
Requests by the reason of cause that this Component get the input focus, if this Component's top-level ancestor is already the focused Window. |
void |
resize |
Deprecated. As of JDK version 1.1, replaced by setSize(int, int). |
void |
resize |
Deprecated. As of JDK version 1.1, replaced by setSize(Dimension). |
void |
revalidate() |
Revalidates the component hierarchy up to the nearest validate root. |
void |
setComponentOrientation |
Sets the language-sensitive orientation that is to be used to order the elements or text within this component. |
void |
setDropTarget |
Associate a DropTarget with this component. |
void |
setEnabled |
Enables or disables this component, depending on the value of the parameter b. |
void |
setFocusable |
Sets the focusable state of this Component to the specified value. |
void |
setFocusTraversalKeysEnabled |
Sets whether focus traversal keys are enabled for this Component. |
void |
setForeground |
Sets the foreground color of this component. |
void |
setIgnoreRepaint |
Sets whether or not paint messages received from the operating system should be ignored. |
void |
setLocale |
Sets the locale of this component. |
void |
setMaximumSize |
Sets the maximum size of this component to a constant value. |
void |
setMixingCutoutShape |
Sets a 'mixing-cutout' shape for this lightweight component. |
void |
setName |
Sets the name of the component to the specified string. |
void |
setPreferredSize |
Sets the preferred size of this component to a constant value. |
void |
show |
Deprecated. As of JDK version 1.1, replaced by setVisible(boolean). |
Dimension |
size() |
Deprecated. As of JDK version 1.1, replaced by getSize(). |
String |
toString() |
Returns a string representation of this component and its values. |
void |
transferFocus() |
Transfers the focus to the next component, as though this Component were the focus owner. |
void |
transferFocusBackward() |
Transfers the focus to the previous component, as though this Component were the focus owner. |
void |
transferFocusUpCycle() |
Transfers the focus up one focus traversal cycle. |
Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait | Modifier and Type | Method | Description |
|---|---|---|
protected Object |
clone() |
Creates and returns a copy of this object. |
boolean |
equals |
Indicates whether some other object is "equal to" this one. |
protected void |
finalize() |
Deprecated, for removal: This API element is subject to removal in a future version. Finalization is deprecated and subject to removal in a future release. |
final Class |
getClass() |
Returns the runtime class of this Object. |
int |
hashCode() |
Returns a hash code value for this object. |
final void |
notify() |
Wakes up a single thread that is waiting on this object's monitor. |
final void |
notifyAll() |
Wakes up all threads that are waiting on this object's monitor. |
final void |
wait() |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted. |
final void |
wait |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. |
final void |
wait |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. |
Constructor Details
Window
public Window(Frame owner)
Frame as its owner. The window will not be focusable unless its owner is showing on the screen.- Parameters:
-
owner- theFrameto act as owner ornullif this window has no owner - Throws:
-
IllegalArgumentException- if theowner'sGraphicsConfigurationis not from a screen device -
HeadlessException- whenGraphicsEnvironment.isHeadlessreturnstrue - See Also:
Window
public Window(Window owner)
Window as its owner. This window will not be focusable unless its nearest owning Frame or Dialog is showing on the screen.- Parameters:
-
owner- theWindowto act as owner ornullif this window has no owner - Throws:
-
IllegalArgumentException- if theowner'sGraphicsConfigurationis not from a screen device -
HeadlessException- whenGraphicsEnvironment.isHeadless()returnstrue - Since:
- 1.2
- See Also:
Window
public Window(Window owner, GraphicsConfiguration gc)
Window and a GraphicsConfiguration of a screen device. The Window will not be focusable unless its nearest owning Frame or Dialog is showing on the screen.- Parameters:
-
owner- the window to act as owner ornullif this window has no owner -
gc- theGraphicsConfigurationof the target screen device; ifgcisnull, the system defaultGraphicsConfigurationis assumed - Throws:
-
IllegalArgumentException- ifgcis not from a screen device -
HeadlessException- whenGraphicsEnvironment.isHeadless()returnstrue - Since:
- 1.3
- See Also:
Method Details
getIconImages
public List<Image> getIconImages()
This method returns a copy of the internally stored list, so all operations on the returned object will not affect the window's behavior.
- Returns:
- the copy of icon images' list for this window, or empty list if this window doesn't have icon images.
- Since:
- 1.6
- See Also:
setIconImages
public void setIconImages(List<? extends Image> icons)
getIconImages will always return a copy of the icons list. Depending on the platform capabilities one or several images of different dimensions will be used as the window's icon.
The icons list can contain MultiResolutionImage images also. Suitable image depending on screen resolution is extracted from base MultiResolutionImage image and added to the icons list while base resolution image is removed from list. The icons list is scanned for the images of most appropriate dimensions from the beginning. If the list contains several images of the same size, the first will be used.
Ownerless windows with no icon specified use platform-default icon. The icon of an owned window may be inherited from the owner unless explicitly overridden. Setting the icon to null or empty list restores the default behavior.
Note : Native windowing systems may use different images of differing dimensions to represent a window, depending on the context (e.g. window decoration, window list, taskbar, etc.). They could also use just a single image for all contexts or no image at all.
- Parameters:
-
icons- the list of icon images to be displayed. - Since:
- 1.6
- See Also:
setIconImage
public void setIconImage(Image image)
This method can be used instead of setIconImages() to specify a single image as a window's icon.
The following statement:
setIconImage(image);
is equivalent to:
ArrayList<Image> imageList = new ArrayList<Image>();
imageList.add(image);
setIconImages(imageList);
Note : Native windowing systems may use different images of differing dimensions to represent a window, depending on the context (e.g. window decoration, window list, taskbar, etc.). They could also use just a single image for all contexts or no image at all.
- Parameters:
-
image- the icon image to be displayed. - Since:
- 1.6
- See Also:
addNotify
pack
public void pack()
setMinimumSize method. If the window and/or its owner are not displayable yet, both of them are made displayable before calculating the preferred size. The Window is validated after its size is being calculated.
- See Also:
setMinimumSize
public void setMinimumSize(Dimension minimumSize)
getMinimumSize will always return this value. If current window's size is less than minimumSize the size of the window is automatically enlarged to honor the minimum size. If the setSize or setBounds methods are called afterwards with a width or height less than that was specified by the setMinimumSize method the window is automatically enlarged to meet the minimumSize value. The minimumSize value also affects the behaviour of the pack method.
The default behavior is restored by setting the minimum size parameter to the null value.
Resizing operation may be restricted if the user tries to resize window below the minimumSize value. This behaviour is platform-dependent.
- Overrides:
-
setMinimumSizein classComponent - Parameters:
-
minimumSize- the new minimum size of this window - Since:
- 1.6
- See Also:
setSize
public void setSize(Dimension d)
d.width and height d.height. This method changes layout-related information, and therefore, invalidates the component hierarchy.
The d.width and d.height values are automatically enlarged if either is less than the minimum size as specified by previous call to setMinimumSize.
The method changes the geometry-related data. Therefore, the native windowing system may ignore such requests, or it may modify the requested data, so that the Window object is placed and sized in a way that corresponds closely to the desktop settings.
setSize
public void setSize(int width, int height)
width and height height. This method changes layout-related information, and therefore, invalidates the component hierarchy.
The width and height values are automatically enlarged if either is less than the minimum size as specified by previous call to setMinimumSize.
The method changes the geometry-related data. Therefore, the native windowing system may ignore such requests, or it may modify the requested data, so that the Window object is placed and sized in a way that corresponds closely to the desktop settings.
setLocation
public void setLocation(int x, int y)
x and y parameters in the coordinate space of this component's parent. This method changes layout-related information, and therefore, invalidates the component hierarchy.
The method changes the geometry-related data. Therefore, the native windowing system may ignore such requests, or it may modify the requested data, so that the Window object is placed and sized in a way that corresponds closely to the desktop settings.
- Overrides:
-
setLocationin classComponent - Parameters:
-
x- the x-coordinate of the new location's top-left corner in the parent's coordinate space -
y- the y-coordinate of the new location's top-left corner in the parent's coordinate space - See Also:
setLocation
public void setLocation(Point p)
p. Point p is given in the parent's coordinate space. This method changes layout-related information, and therefore, invalidates the component hierarchy.
The method changes the geometry-related data. Therefore, the native windowing system may ignore such requests, or it may modify the requested data, so that the Window object is placed and sized in a way that corresponds closely to the desktop settings.
- Overrides:
-
setLocationin classComponent - Parameters:
-
p- the point defining the top-left corner of the new location, given in the coordinate space of this component's parent - See Also:
reshape
@Deprecated public void reshape(int x, int y, int width, int height)
setBounds(int, int, int, int).ComponentsetVisible
public void setVisible(boolean b)
Window depending on the value of parameter b. If the method shows the window then the window is also made focused under the following conditions:
- The
Windowmeets the requirements outlined in theisFocusableWindow()method. - The
Window'sautoRequestFocusproperty is of thetruevalue. - Native windowing system allows the
Windowto get focused.
autoRequestFocus property). The property is not taken into account if the window is a modal dialog, which blocks the currently focused window. Developers must never assume that the window is the focused or active window until it receives a WINDOW_GAINED_FOCUS or WINDOW_ACTIVATED event.
- Overrides:
-
setVisiblein classComponent - Parameters:
-
b- iftrue, makes theWindowvisible, otherwise hides theWindow. If theWindowand/or its owner are not yet displayable, both are made displayable. TheWindowwill be validated prior to being made visible. If theWindowis already visible, this will bring theWindowto the front.If
false, hides thisWindow, its subcomponents, and all of its owned children. TheWindowand its subcomponents can be made visible again with a call to#setVisible(true). - See Also:
show
@Deprecated public void show()
setVisible(boolean).hide
@Deprecated public void hide()
setVisible(boolean).show.dispose
public void dispose()
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:
toFront
public void toFront()
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.
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) under the following conditions:
- The window meets the requirements outlined in the
isFocusableWindow()method. - The window's property
autoRequestFocusis of thetruevalue. - Native windowing system allows the window to get focused.
If this method causes this Window to be focused, and this Window is a Frame or a Dialog, it will also become activated. If this Window is focused, but it is not a Frame or a Dialog, then the first Frame or Dialog that is an owner of this Window will be activated.
If this window is blocked by modal dialog, then the blocking dialog is brought to the front and remains above the blocked window.
- See Also:
toBack
public void toBack()
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:
getToolkit
public Toolkit getToolkit()
- Overrides:
-
getToolkitin classComponent - Returns:
- the toolkit of this window.
- See Also:
getWarningString
@Deprecated(since="24", forRemoval=true) public final String getWarningString()
Warning strings are no longer applicable, so this method always returns null and may be removed in a future release.
- Returns:
- null
getLocale
getInputContext
public InputContext getInputContext()
- Overrides:
-
getInputContextin classComponent - Returns:
- the input context used by this component;
nullif no context can be determined - Since:
- 1.2
- See Also:
setCursor
public void setCursor(Cursor cursor)
The method may have no visual effect if the Java platform implementation and/or the native system do not support changing the mouse cursor shape.
getOwner
public Window getOwner()
- Returns:
- the owner of this window
- Since:
- 1.2
getOwnedWindows
public Window[] getOwnedWindows()
- Returns:
- the array of all the owned windows
- Since:
- 1.2
getWindows
public static Window[] getWindows()
Windows, both owned and ownerless, created by this application. Warning: this method may return system created windows, such as a print dialog. Applications should not assume the existence of these dialogs, nor should an application assume anything about these dialogs such as component positions, LayoutManagers or serialization.
- Returns:
- the array of all the
Windows created by the application - Since:
- 1.6
- See Also:
getOwnerlessWindows
public static Window[] getOwnerlessWindows()
Windows created by this application that have no owner. They include Frames and ownerless Dialogs and Windows. Warning: this method may return system created windows, such as a print dialog. Applications should not assume the existence of these dialogs, nor should an application assume anything about these dialogs such as component positions, LayoutManagers or serialization.
- Returns:
- the array of all the ownerless
Windows created by this application - Since:
- 1.6
- See Also:
setModalExclusionType
public void setModalExclusionType(Dialog.ModalExclusionType exclusionType)
Dialog.ModalExclusionType for possible modal exclusion types. If the given type is not supported, NO_EXCLUDE is used.
Note: changing the modal exclusion type for a visible window may have no effect until it is hidden and then shown again.
- Parameters:
-
exclusionType- the modal exclusion type for this window; anullvalue is equivalent toNO_EXCLUDE - Since:
- 1.6
- See Also:
getModalExclusionType
public Dialog.ModalExclusionType getModalExclusionType()
- Returns:
- the modal exclusion type of this window
- Since:
- 1.6
- See Also:
addWindowListener
public void addWindowListener(WindowListener l)
Refer to AWT Threading Issues for details on AWT's threading model.
- Parameters:
-
l- the window listener - See Also:
addWindowStateListener
public void addWindowStateListener(WindowStateListener l)
l is null, no exception is thrown and no action is performed. Refer to AWT Threading Issues for details on AWT's threading model.
- Parameters:
-
l- the window state listener - Since:
- 1.4
- See Also:
addWindowFocusListener
public void addWindowFocusListener(WindowFocusListener l)
Refer to AWT Threading Issues for details on AWT's threading model.
- Parameters:
-
l- the window focus listener - Since:
- 1.4
- See Also:
removeWindowListener
public void removeWindowListener(WindowListener l)
Refer to AWT Threading Issues for details on AWT's threading model.
- Parameters:
-
l- the window listener - See Also:
removeWindowStateListener
public void removeWindowStateListener(WindowStateListener l)
l is null, no exception is thrown and no action is performed. Refer to AWT Threading Issues for details on AWT's threading model.
- Parameters:
-
l- the window state listener - Since:
- 1.4
- See Also:
removeWindowFocusListener
public void removeWindowFocusListener(WindowFocusListener l)
Refer to AWT Threading Issues for details on AWT's threading model.
- Parameters:
-
l- the window focus listener - Since:
- 1.4
- See Also:
getWindowListeners
public WindowListener[] getWindowListeners()
- Returns:
- all of this window's
WindowListeners or an empty array if no window listeners are currently registered - Since:
- 1.4
- See Also:
getWindowFocusListeners
public WindowFocusListener[] getWindowFocusListeners()
- Returns:
- all of this window's
WindowFocusListeners or an empty array if no window focus listeners are currently registered - Since:
- 1.4
- See Also:
getWindowStateListeners
public WindowStateListener[] getWindowStateListeners()
- Returns:
- all of this window's
WindowStateListeners or an empty array if no window state listeners are currently registered - Since:
- 1.4
- See Also:
getListeners
public <T extends EventListener> T[] getListeners(Class<T> listenerType)
FooListeners upon this Window. FooListeners are registered using the addFooListener method. You can specify the listenerType argument with a class literal, such as FooListener.class. For example, you can query a Window w for its window listeners with the following code:
WindowListener[] wls = (WindowListener[])(w.getListeners(WindowListener.class));If no such listeners exist, this method returns an empty array.
- Overrides:
-
getListenersin classContainer - Type Parameters:
T- the type of the listeners- Parameters:
-
listenerType- the type of listeners requested; this parameter should specify an interface that descends fromjava.util.EventListener - Returns:
- an array of all objects registered as
FooListeners on this window, or an empty array if no such listeners have been added - Throws:
-
ClassCastException- iflistenerTypedoesn't specify a class or interface that implementsjava.util.EventListener -
NullPointerException- iflistenerTypeisnull - Since:
- 1.3
- See Also:
processEvent
protected void processEvent(AWTEvent e)
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:
-
processEventin classContainer - Parameters:
-
e- the event - See Also:
processWindowEvent
protected void processWindowEvent(WindowEvent e)
- A WindowListener object is registered via
addWindowListener - Window events are enabled via
enableEvents
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:
processWindowFocusEvent
protected void processWindowFocusEvent(WindowEvent e)
- a WindowFocusListener is registered via
addWindowFocusListener - Window focus events are enabled via
enableEvents
Note that if the event parameter is null the behavior is unspecified and may result in an exception.
- Parameters:
-
e- the window focus event - Since:
- 1.4
- See Also:
processWindowStateEvent
protected void processWindowStateEvent(WindowEvent e)
WindowStateListener objects. NOTE: this method will not be called unless window state events are enabled for this window. This happens when one of the following occurs: - a
WindowStateListeneris registered viaaddWindowStateListener - window state events are enabled via
enableEvents
Note that if the event parameter is null the behavior is unspecified and may result in an exception.
- Parameters:
-
e- the window state event - Since:
- 1.4
- See Also:
setAlwaysOnTop
public final void setAlwaysOnTop(boolean alwaysOnTop)
If some other window is already always-on-top then the relative order between these windows is unspecified (depends on platform). No window can be brought to be over the always-on-top window except maybe another always-on-top window.
All windows owned by an always-on-top window inherit this state and automatically become always-on-top. If a window ceases to be always-on-top, the windows that it owns will no longer be always-on-top. When an always-on-top window is sent toBack, its always-on-top state is set to false.
When this method is called on a window with a value of true, and the window is visible and the platform supports always-on-top for this window, the window is immediately brought forward, "sticking" it in the top-most position. If the window isn`t currently visible, this method sets the always-on-top state to true but does not bring the window forward. When the window is later shown, it will be always-on-top.
When this method is called on a window with a value of false the always-on-top state is set to normal. It may also cause an unspecified, platform-dependent change in the z-order of top-level windows, but other always-on-top windows will remain in top-most position. Calling this method with a value of false on a window that has a normal state has no effect.
Note: some platforms might not support always-on-top windows. To detect if always-on-top windows are supported by the current platform, use Toolkit.isAlwaysOnTopSupported() and isAlwaysOnTopSupported(). If always-on-top mode isn't supported for this window or this window's toolkit does not support always-on-top windows, calling this method has no effect.
- Parameters:
-
alwaysOnTop- true if the window should always be above other windows - Since:
- 1.5
- See Also:
isAlwaysOnTopSupported
public boolean isAlwaysOnTopSupported()
- Returns:
-
true, if the always-on-top mode is supported for this window and this window's toolkit supports always-on-top windows,falseotherwise - Since:
- 1.6
- See Also:
isAlwaysOnTop
public final boolean isAlwaysOnTop()
- Returns:
-
true, if the window is in always-on-top state,falseotherwise - Since:
- 1.5
- See Also:
getFocusOwner
public Component getFocusOwner()
- Returns:
- the child Component with focus, or null if this Window is not focused
- See Also:
getMostRecentFocusOwner
public Component getMostRecentFocusOwner()
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:
isActive
public boolean isActive()
- Returns:
- whether this is the active Window.
- Since:
- 1.4
- See Also:
isFocused
public boolean isFocused()
If the focused Window is a Frame or a Dialog it is also the active Window. Otherwise, the active Window is the first Frame or Dialog that is an owner of the focused Window.
- Returns:
- whether this is the focused Window.
- Since:
- 1.4
- See Also:
getFocusTraversalKeys
public Set<AWTKeyStroke> getFocusTraversalKeys(int id)
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:
-
getFocusTraversalKeysin classContainer - 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:
setFocusCycleRoot
public final void setFocusCycleRoot(boolean focusCycleRoot)
- Overrides:
-
setFocusCycleRootin classContainer - Parameters:
-
focusCycleRoot- this value is ignored - Since:
- 1.4
- See Also:
isFocusCycleRoot
public final boolean isFocusCycleRoot()
true because all Windows must be roots of a focus traversal cycle.- Overrides:
-
isFocusCycleRootin classContainer - Returns:
true- Since:
- 1.4
- See Also:
getFocusCycleRootAncestor
public final Container getFocusCycleRootAncestor()
null because Windows have no ancestors; they represent the top of the Component hierarchy.- Overrides:
-
getFocusCycleRootAncestorin classComponent - Returns:
null- Since:
- 1.4
- See Also:
isFocusableWindow
public final boolean isFocusableWindow()
true. For a Window which is not a Frame or Dialog to be focusable, its focusable Window state must be set to true, its nearest owning Frame or Dialog 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:
-
trueif this Window can be the focused Window;falseotherwise - Since:
- 1.4
- See Also:
getFocusableWindowState
public boolean getFocusableWindowState()
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:
setFocusableWindowState
public void setFocusableWindowState(boolean focusableWindowState)
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. Setting the focusability state on a visible Window can have a delayed effect on some platforms — the actual change may happen only when the Window becomes hidden and then visible again. To ensure consistent behavior across platforms, set the Window's focusable state when the Window is invisible and then show it.
- Parameters:
-
focusableWindowState- whether this Window can be the focused Window - Since:
- 1.4
- See Also:
setAutoRequestFocus
public void setAutoRequestFocus(boolean autoRequestFocus)
setVisible(true)), or being moved to the front (with a call to toFront()). Note that setVisible(true) may be called indirectly (e.g. when showing an owner of the window makes the window to be shown). toFront() may also be called indirectly (e.g. when setVisible(true) is called on already visible window). In all such cases this property takes effect as well.
The value of the property is not inherited by owned windows.
- Parameters:
-
autoRequestFocus- whether this window should be focused on subsequently being shown or being moved to the front - Since:
- 1.7
- See Also:
isAutoRequestFocus
public boolean isAutoRequestFocus()
setVisible(true)), or being moved to the front (with a call to toFront()). By default, the window has autoRequestFocus value of true.
- Returns:
-
autoRequestFocusvalue - Since:
- 1.7
- See Also:
addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener listener)
- this Window's font ("font")
- this Window's background color ("background")
- this Window's foreground color ("foreground")
- this Window's focusability ("focusable")
- this Window's focus traversal keys enabled state ("focusTraversalKeysEnabled")
- this Window's Set of FORWARD_TRAVERSAL_KEYS ("forwardFocusTraversalKeys")
- this Window's Set of BACKWARD_TRAVERSAL_KEYS ("backwardFocusTraversalKeys")
- this Window's Set of UP_CYCLE_TRAVERSAL_KEYS ("upCycleFocusTraversalKeys")
- this Window's Set of DOWN_CYCLE_TRAVERSAL_KEYS ("downCycleFocusTraversalKeys")
- this Window's focus traversal policy ("focusTraversalPolicy")
- this Window's focusable Window state ("focusableWindowState")
- this Window's always-on-top state("alwaysOnTop")
If listener is null, no exception is thrown and no action is performed.
- Overrides:
-
addPropertyChangeListenerin classContainer - Parameters:
-
listener- the PropertyChangeListener to be added - See Also:
addPropertyChangeListener
public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
- this Window's font ("font")
- this Window's background color ("background")
- this Window's foreground color ("foreground")
- this Window's focusability ("focusable")
- this Window's focus traversal keys enabled state ("focusTraversalKeysEnabled")
- this Window's Set of FORWARD_TRAVERSAL_KEYS ("forwardFocusTraversalKeys")
- this Window's Set of BACKWARD_TRAVERSAL_KEYS ("backwardFocusTraversalKeys")
- this Window's Set of UP_CYCLE_TRAVERSAL_KEYS ("upCycleFocusTraversalKeys")
- this Window's Set of DOWN_CYCLE_TRAVERSAL_KEYS ("downCycleFocusTraversalKeys")
- this Window's focus traversal policy ("focusTraversalPolicy")
- this Window's focusable Window state ("focusableWindowState")
- this Window's always-on-top state("alwaysOnTop")
If listener is null, no exception is thrown and no action is performed.
- Overrides:
-
addPropertyChangeListenerin classContainer - Parameters:
-
propertyName- one of the property names listed above -
listener- the PropertyChangeListener to be added - See Also:
isValidateRoot
public boolean isValidateRoot()
Window objects are the validate roots, and, therefore, they override this method to return true.
- Overrides:
-
isValidateRootin classContainer - Returns:
true- Since:
- 1.7
- See Also:
postEvent
@Deprecated public boolean postEvent(Event e)
dispatchEvent(AWTEvent).MenuContainer- Specified by:
-
postEventin interfaceMenuContainer - Overrides:
-
postEventin classComponent - Parameters:
-
e- the event to dispatch - Returns:
- the results of posting the event
isShowing
applyResourceBundle
@Deprecated public void applyResourceBundle(ResourceBundle rb)
Component.applyComponentOrientation.- Parameters:
-
rb- the resource bundle
applyResourceBundle
@Deprecated public void applyResourceBundle(String rbName)
Component.applyComponentOrientation.- Parameters:
-
rbName- the resource name
setType
public void setType(Window.Type type)
- Parameters:
-
type- the window type - Throws:
-
IllegalComponentStateException- if the window is displayable. -
IllegalArgumentException- if the type isnull - Since:
- 1.7
- See Also:
getType
public Window.Type getType()
- Returns:
- the type of the window
- Since:
- 1.7
- See Also:
getAccessibleContext
public AccessibleContext getAccessibleContext()
- Specified by:
-
getAccessibleContextin interfaceAccessible - Overrides:
-
getAccessibleContextin classComponent - Returns:
- an AccessibleAWTWindow that serves as the AccessibleContext of this Window
- Since:
- 1.3
setLocationRelativeTo
public void setLocationRelativeTo(Component c)
The target screen mentioned below is a screen to which the window should be placed after the setLocationRelativeTo method is called.
- If the component is
null, or theGraphicsConfigurationassociated with this component isnull, the window is placed in the center of the screen. The center point can be obtained with theGraphicsEnvironment.getCenterPointmethod. - If the component is not
null, but it is not currently showing, the window is placed in the center of the target screen defined by theGraphicsConfigurationassociated with this component. - If the component is not
nulland is shown on the screen, then the window is located in such a way that the center of the window coincides with the center of the component.
If the screens configuration does not allow the window to be moved from one screen to another, then the window is only placed at the location determined according to the above conditions and its GraphicsConfiguration is not changed.
Note: If the lower edge of the window is out of the screen, then the window is placed to the side of the Component that is closest to the center of the screen. So if the component is on the right part of the screen, the window is placed to its left, and vice versa.
If after the window location has been calculated, the upper, left, or right edge of the window is out of the screen, then the window is located in such a way that the upper, left, or right edge of the window coincides with the corresponding edge of the screen. If both left and right edges of the window are out of the screen, the window is placed at the left side of the screen. The similar placement will occur if both top and bottom edges are out of the screen. In that case, the window is placed at the top side of the screen.
The method changes the geometry-related data. Therefore, the native windowing system may ignore such requests, or it may modify the requested data, so that the Window object is placed and sized in a way that corresponds closely to the desktop settings.
- Parameters:
-
c- the component in relation to which the window's location is determined - Since:
- 1.4
- See Also:
createBufferStrategy
public void createBufferStrategy(int numBuffers)
BufferStrategy with that number of buffers. A page-flipping strategy is attempted first, then a blitting strategy using accelerated buffers. Finally, an unaccelerated blitting strategy is used. Each time this method is called, the existing buffer strategy for this component is discarded.
- Parameters:
-
numBuffers- number of buffers to create - Throws:
-
IllegalArgumentException- if numBuffers is less than 1. -
IllegalStateException- if the component is not displayable - Since:
- 1.4
- See Also:
createBufferStrategy
public void createBufferStrategy(int numBuffers, BufferCapabilities caps) throws AWTException
Each time this method is called, the existing buffer strategy for this component is discarded.
- Parameters:
-
numBuffers- number of buffers to create, including the front buffer -
caps- the required capabilities for creating the buffer strategy; cannot benull - Throws:
-
AWTException- if the capabilities supplied could not be supported or met; this may happen, for example, if there is not enough accelerated memory currently available, or if page flipping is specified but not possible. -
IllegalArgumentException- if numBuffers is less than 1, or if caps isnull - Since:
- 1.4
- See Also:
getBufferStrategy
public BufferStrategy getBufferStrategy()
BufferStrategy used by this component. This method will return null if a BufferStrategy has not yet been created or has been disposed.- Returns:
- the buffer strategy used by this component
- Since:
- 1.4
- See Also:
setLocationByPlatform
public void setLocationByPlatform(boolean locationByPlatform)
getLocation) the next time the Window is made visible. This behavior resembles a native window shown without programmatically setting its location. Most windowing systems cascade windows if their locations are not explicitly set. The actual location is determined once the window is shown on the screen. This behavior can also be enabled by setting the System Property "java.awt.Window.locationByPlatform" to "true", though calls to this method take precedence.
Calls to setVisible, setLocation and setBounds after calling setLocationByPlatform clear this property of the Window.
For example, after the following code is executed:
setLocationByPlatform(true); setVisible(true); boolean flag = isLocationByPlatform();The window will be shown at platform's default location and
flag will be false. In the following sample:
setLocationByPlatform(true); setLocation(10, 10); boolean flag = isLocationByPlatform(); setVisible(true);The window will be shown at (10, 10) and
flag will be false.- Parameters:
-
locationByPlatform-trueif this Window should appear at the default location,falseif at the current location - Throws:
-
IllegalComponentStateException- if the window is showing on screen and locationByPlatform istrue. - Since:
- 1.5
- See Also:
isLocationByPlatform
public boolean isLocationByPlatform()
true if this Window will appear at the default location for the native windowing system the next time this Window is made visible. This method always returns false if the Window is showing on the screen.- Returns:
- whether this Window will appear at the default location
- Since:
- 1.5
- See Also:
setBounds
public void setBounds(int x, int y, int width, int height)
x and y, and the new size is specified by width and height. This method changes layout-related information, and therefore, invalidates the component hierarchy.
The width or height values are automatically enlarged if either is less than the minimum size as specified by previous call to setMinimumSize.
The method changes the geometry-related data. Therefore, the native windowing system may ignore such requests, or it may modify the requested data, so that the Window object is placed and sized in a way that corresponds closely to the desktop settings.
setBounds
public void setBounds(Rectangle r)
r. This component's new position is specified by r.x and r.y, and its new size is specified by r.width and r.height This method changes layout-related information, and therefore, invalidates the component hierarchy.
The r.width or r.height values will be automatically enlarged if either is less than the minimum size as specified by previous call to setMinimumSize.
The method changes the geometry-related data. Therefore, the native windowing system may ignore such requests, or it may modify the requested data, so that the Window object is placed and sized in a way that corresponds closely to the desktop settings.
getOpacity
public float getOpacity()
- Returns:
- the opacity of the window
- Since:
- 1.7
- See Also:
setOpacity
public void setOpacity(float opacity)
The opacity value is in the range [0..1]. Note that setting the opacity level of 0 may or may not disable the mouse event handling on this window. This is a platform-dependent behavior.
The following conditions must be met in order to set the opacity value less than 1.0f:
- The
TRANSLUCENTtranslucency must be supported by the underlying system - The window must be undecorated (see
Frame.setUndecorated(boolean)andDialog.setUndecorated(boolean)) - The window must not be in full-screen mode (see
GraphicsDevice.setFullScreenWindow(Window))
If the requested opacity value is less than 1.0f, and any of the above conditions are not met, the window opacity will not change, and the IllegalComponentStateException will be thrown.
The translucency levels of individual pixels may also be effected by the alpha component of their color (see setBackground(Color)) and the current shape of this window (see setShape(Shape)).
- Parameters:
-
opacity- the opacity level to set to the window - Throws:
-
IllegalArgumentException- if the opacity is out of the range [0..1] -
IllegalComponentStateException- if the window is decorated and the opacity is less than1.0f -
IllegalComponentStateException- if the window is in full screen mode, and the opacity is less than1.0f -
UnsupportedOperationException- if theGraphicsDevice.WindowTranslucency#TRANSLUCENT TRANSLUCENTtranslucency is not supported and the opacity is less than1.0f - Since:
- 1.7
- See Also:
getShape
public Shape getShape()
setShape(shape), but it is guaranteed to represent the same shape.- Returns:
- the shape of the window or
nullif no shape is specified for the window - Since:
- 1.7
- See Also:
setShape
public void setShape(Shape shape)
Setting a shape cuts off some parts of the window. Only the parts that belong to the given Shape remain visible and clickable. If the shape argument is null, this method restores the default shape, making the window rectangular on most platforms.
The following conditions must be met to set a non-null shape:
- The
PERPIXEL_TRANSPARENTtranslucency must be supported by the underlying system - The window must be undecorated (see
Frame.setUndecorated(boolean)andDialog.setUndecorated(boolean)) - The window must not be in full-screen mode (see
GraphicsDevice.setFullScreenWindow(Window))
If the requested shape is not null, and any of the above conditions are not met, the shape of this window will not change, and either the UnsupportedOperationException or
IllegalComponentStateException will be thrown.
The translucency levels of individual pixels may also be effected by the alpha component of their color (see setBackground(Color)) and the opacity value (see setOpacity(float)). See GraphicsDevice.WindowTranslucency for more details.
- Parameters:
-
shape- the shape to set to the window - Throws:
-
IllegalComponentStateException- if the shape is notnulland the window is decorated -
IllegalComponentStateException- if the shape is notnulland the window is in full-screen mode -
UnsupportedOperationException- if the shape is notnullandPERPIXEL_TRANSPARENTtranslucency is not supported - Since:
- 1.7
- See Also:
getBackground
public Color getBackground()
Note that the alpha component of the returned color indicates whether the window is in the non-opaque (per-pixel translucent) mode.
- Overrides:
-
getBackgroundin classComponent - Returns:
- this component's background color
- See Also:
setBackground
public void setBackground(Color bgColor)
If the windowing system supports the PERPIXEL_TRANSLUCENT translucency, the alpha component of the given background color may effect the mode of operation for this window: it indicates whether this window must be opaque (alpha equals 1.0f) or per-pixel translucent (alpha is less than 1.0f). If the given background color is null, the window is considered completely opaque.
All the following conditions must be met to enable the per-pixel transparency mode for this window:
- The
PERPIXEL_TRANSLUCENTtranslucency must be supported by the graphics device where this window is located - The window must be undecorated (see
Frame.setUndecorated(boolean)andDialog.setUndecorated(boolean)) - The window must not be in full-screen mode (see
GraphicsDevice.setFullScreenWindow(Window))
If the alpha component of the requested background color is less than 1.0f, and any of the above conditions are not met, the background color of this window will not change, the alpha component of the given background color will not affect the mode of operation for this window, and either the UnsupportedOperationException or
IllegalComponentStateException will be thrown.
When the window is per-pixel translucent, the drawing sub-system respects the alpha value of each individual pixel. If a pixel gets painted with the alpha color component equal to zero, it becomes visually transparent. If the alpha of the pixel is equal to 1.0f, the pixel is fully opaque. Interim values of the alpha color component make the pixel semi-transparent. In this mode, the background of the window gets painted with the alpha value of the given background color. If the alpha value of the argument of this method is equal to 0, the background is not painted at all.
The actual level of translucency of a given pixel also depends on window opacity (see setOpacity(float)), as well as the current shape of this window (see setShape(Shape)).
Note that painting a pixel with the alpha value of 0 may or may not disable the mouse event handling on this pixel. This is a platform-dependent behavior. To make sure the mouse events do not get dispatched to a particular pixel, the pixel must be excluded from the shape of the window.
Enabling the per-pixel translucency mode may change the graphics configuration of this window due to the native platform requirements.
- Overrides:
-
setBackgroundin classComponent - Parameters:
-
bgColor- the color to become this window's background color. - Throws:
-
IllegalComponentStateException- if the alpha value of the given background color is less than1.0fand the window is decorated -
IllegalComponentStateException- if the alpha value of the given background color is less than1.0fand the window is in full-screen mode -
UnsupportedOperationException- if the alpha value of the given background color is less than1.0fandPERPIXEL_TRANSLUCENTtranslucency is not supported - See Also:
isOpaque
public boolean isOpaque()
The method returns false if the background color of the window is not null and the alpha component of the color is less than 1.0f. The method returns true otherwise.
paint
public void paint(Graphics g)
© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Component.applyComponentOrientation.