java.awt.Frame
that adds support for
the JFC/Swing component architecture.
You can find task-oriented documentation about using JFrame
in The Java Tutorial, in the section
How to Make Frames.
The JFrame
class is slightly incompatible with Frame
.
Like all other JFC/Swing top-level containers,
a JFrame
contains a JRootPane
as its only child.
The content pane provided by the root pane should,
as a rule, contain
all the non-menu components displayed by the JFrame
.
This is different from the AWT Frame
case.
As a conveniance add
and its variants, remove
and
setLayout
have been overridden to forward to the
contentPane
as necessary. This means you can write:
frame.add(child);And the child will be added to the contentPane. The content pane will always be non-null. Attempting to set it to null will cause the JFrame to throw an exception. The default content pane will have a BorderLayout manager set on it. Refer to javax.swing.RootPaneContainer for details on adding, removing and setting the
LayoutManager
of a JFrame
.
Unlike a Frame
, a JFrame
has some notion of how to
respond when the user attempts to close the window. The default behavior
is to simply hide the JFrame when the user closes the window. To change the
default behavior, you invoke the method
#setDefaultCloseOperation
.
To make the JFrame
behave the same as a Frame
instance, use
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE)
.
For more information on content panes and other features that root panes provide, see Using Top-Level Containers in The Java Tutorial.
In a multi-screen environment, you can create a JFrame
on a different screen device. See java.awt.Frame
for more
information.
Warning:
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeansTM
has been added to the java.beans
package.
Please see java.beans.XMLEncoder
.
This constructor sets the component's locale property to the value
returned by JComponent.getDefaultLocale
.
Frame
in the specified
GraphicsConfiguration
of
a screen device and a blank title.
This constructor sets the component's locale property to the value
returned by JComponent.getDefaultLocale
.
Frame
with the
specified title.
This constructor sets the component's locale property to the value
returned by JComponent.getDefaultLocale
.
JFrame
with the specified title and the
specified GraphicsConfiguration
of a screen device.
This constructor sets the component's locale property to the value
returned by JComponent.getDefaultLocale
.
getAlignmentY
.
Specifies an alignment to the bottom of the component.getAlignmentY
and
getAlignmentX
. Specifies an alignment to
the center of the componentNote: 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.
SecurityException
may be thrown.
It is recommended you only use this in an application.
getAlignmentX
.
Specifies an alignment to the left side of the component.MAXIMIZED_VERT | MAXIMIZED_HORIZ
.
Note that the correct test for frame being fully maximized is
(state & Frame.MAXIMIZED_BOTH) == Frame.MAXIMIZED_BOTH
To test is frame is maximized in some direction use
(state & Frame.MAXIMIZED_BOTH) != 0
getAlignmentX
.
Specifies an alignment to the right side of the component.getAlignmentY()
.
Specifies an alignment to the top of the component.
Note: If a component has been added to a container that
has been displayed, validate
must be
called on that container to display the new component.
If multiple components are being added, you can improve
efficiency by calling validate
only once,
after all the components have been added.
Note: If a component has been added to a container that
has been displayed, validate
must be
called on that container to display the new component.
If multiple components are being added, you can improve
efficiency by calling validate
only once,
after all the components have been added.
Note: If a component has been added to a container that
has been displayed, validate
must be
called on that container to display the new component.
If multiple components are being added, you can improve
efficiency by calling validate
only once,
after all the components have been added.
Note: If a component has been added to a container that
has been displayed, validate
must be
called on that container to display the new component.
If multiple components are being added, you can improve
efficiency by calling validate
only once,
after all the components have been added.
This method is obsolete as of 1.1. Please use the
method add(Component, Object)
instead.
l
is null
,
no exception is thrown and no action is performed.l
is null
,
no exception is thrown and no action is performed.l
is null
,
no exception is thrown and no action is performed.l
is null
,
no exception is thrown and no action is performed.getInputMethodRequests
to return an
InputMethodRequests
instance.
If listener l
is null
,
no exception is thrown and no action is performed.l
is null
,
no exception is thrown and no action is performed.l
is null
,
no exception is thrown and no action is performed.For information on how mouse wheel events are dispatched, see the class description for MouseWheelEvent .
If l is null
, no exception is thrown and no
action is performed.
If listener is null, no exception is thrown and no action is performed.
If listener is null, no exception is thrown and no action is performed.
l
is null,
no exception is thrown and no action is performed.ComponentOrientation
property of this container
and all components contained within it.false
, this Container is inheriting the
Set from an ancestor, or from the current KeyboardFocusManager.
This method does not cause the image to begin loading. An
application must use the prepareImage
method
to force the loading of an image.
Information on the flags returned by this method can be found
with the discussion of the ImageObserver
interface.
This method does not cause the image to begin loading. An
application must use the prepareImage
method
to force the loading of an image.
The checkImage
method of Component
calls its peer's checkImage
method to calculate
the flags. If this component does not yet have a peer, the
component's toolkit's checkImage
method is called
instead.
Information on the flags returned by this method can be found
with the discussion of the ImageObserver
interface.
x
and y
are defined to be
relative to the coordinate system of this component.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.
Each time this method is called, the existing buffer strategy for this component is discarded.
VolatileImage
interface.processEvent
before returning for 1.1-style
events which have been enabled for the Component
.Window
, its subcomponents, and all of its owned
children. That is, the resources for these Component
s
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.
validate
method instead.
The equals
method implements an equivalence relation
on non-null object references:
x
, x.equals(x)
should return
true
.
x
and y
, x.equals(y)
should return true
if and only if
y.equals(x)
returns true
.
x
, y
, and z
, if
x.equals(y)
returns true
and
y.equals(z)
returns true
, then
x.equals(z)
should return true
.
x
and y
, multiple invocations of
x.equals(y) consistently return true
or consistently return false
, provided no
information used in equals
comparisons on the
objects is modified.
x
,
x.equals(null)
should return false
.
The equals method for class Object
implements
the most discriminating possible equivalence relation on objects;
that is, for any non-null reference values x
and
y
, this method returns true
if and only
if x
and y
refer to the same object
(x == y
has the value true
).
Note that it is generally necessary to override the hashCode method whenever this method is overridden, so as to maintain the general contract for the hashCode method, which states that equal objects must have equal hash codes.
The findComponentAt method is different from getComponentAt in that getComponentAt only searches the Container's immediate children; if the containing component is a Container, findComponentAt will search that child to find a nested component.
The findComponentAt method is different from getComponentAt in that getComponentAt only searches the Container's immediate children; if the containing component is a Container, findComponentAt will search that child to find a nested component.
Rectangle
object. The bounds specify this
component's width, height, and location relative to
its parent.null
a new
Rectangle
is allocated.
This version of getBounds
is useful if the caller
wants to avoid allocating a new Rectangle
object
on the heap.ColorModel
used to display
the component on the output device.LayoutManager
and Component
subclasses that wish to respect orientation should call this method to
get the component's orientation before performing layout or drawing.Cursor.DEFAULT_CURSOR
is returned.DropTarget
associated with this
Component
.NORMAL
ICONIFIED
MAXIMIZED_HORIZ
MAXIMIZED_VERT
MAXIMIZED_BOTH
MAXIMIZED_HORIZ
and MAXIMIZED_VERT
.
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
.
null
because Windows have no ancestors; they
represent the top of the Component hierarchy.
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.
null
if this component is currently not
displayable.component.getBounds().heightcomponent.getSize().height
because it
doesn't cause any heap allocations.InputMethodRequests
instance.
At the same time, it also has to handle input method events.
A Frame
object, for example, has a top inset that
corresponds to the height of the frame's title bar.
FooListener
s
upon this Window
.
FooListener
s 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.
Locale
object that is associated
with this window, if the locale has been set.
If no locale has been set, then the default locale
is returned.
Due to the asynchronous nature of native event handling, this
method can return outdated values (for instance, after several calls
of setLocation()
in rapid succession). For this
reason, the recommended method of obtaining a component's position is
within java.awt.event.ComponentListener.componentMoved()
,
which is called after the operating system has finished moving the
component.
null
a new
Point
is allocated.
This version of getLocation
is useful if the
caller wants to avoid allocating a new Point
object on the heap.Integer.MAX_VALUE
to indicate
that system supplied values for this field must be used.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.Component
's
coordinate space if the Component
is directly under the mouse
pointer, otherwise returns null
.
If the Component
is not showing on the screen, this method
returns null
even if the mouse pointer is above the area
where the Component
would be displayed.
If the Component
is partially or fully obscured by other
Component
s or native windows, this method returns a non-null
value only if the mouse pointer is located above the unobscured part of the
Component
.
For Container
s it returns a non-null value if the mouse is
above the Container
itself or above any of its descendants.
Use
if you need to exclude children.
Sometimes the exact mouse coordinates are not important, and the only thing
that matters is whether a specific Component
is under the mouse
pointer. If the return value of this method is null
, mouse
pointer is not directly above the Component
.
Container
's
coordinate space if the Container
is under the mouse pointer,
otherwise returns null
.
This method is similar to
with the exception
that it can take the Container
's children into account.
If allowChildren
is false
, this method will return
a non-null value only if the mouse pointer is above the Container
directly, not above the part obscured by children.
If allowChildren
is true
, this method returns
a non-null value if the mouse pointer is above Container
or any
of its descendants.Dimension
object. The height
field of the Dimension
object contains
this component's height, and the width
field of the Dimension
object contains
this component's width.null
a new
Dimension
object is allocated. This version of
getSize
is useful if the caller wants to avoid
allocating a new Dimension
object on the heap.In older versions of JDK a frame state could only be NORMAL or ICONIFIED. Since JDK 1.4 set of supported frame states is expanded and frame state is represented as a bitwise mask.
For compatibility with old programs this method still returns
Frame.NORMAL
and Frame.ICONIFIED
but
it only reports the iconic state of the frame, other aspects of
frame state are not reported by this method.
checkTopLevelWindow
method returns
false
when this window is passed to it as an
argument.
If the window is secure, then getWarningString
returns null
. If the window is insecure, this
method checks for the system property
awt.appletWarning
and returns the string value of that property.
component.getBounds().width
,
or component.getSize().width
because it
doesn't cause any heap allocations.component.getBounds().x
,
or component.getLocation().x
because it doesn't
cause any heap allocations.component.getBounds().y
,
or component.getLocation().y
because it
doesn't cause any heap allocations.true
if this Component
is the
focus owner. This method is obsolete, and has been replaced by
isFocusOwner()
.java.util.Hashtable
.
The general contract of hashCode
is:
hashCode
method on each of
the two objects must produce the same integer result.
As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)
imageUpdate
method of an ImageObserver
is called when more information about an
image which had been previously requested using an asynchronous
routine such as the drawImage
method of
Graphics
becomes available.
See the definition of imageUpdate
for
more information on this method and its arguments.
The imageUpdate
method of Component
incrementally draws an image on the component as more of the bits
of the image are available.
If the system property awt.image.incrementaldraw
is missing or has the value true
, the image is
incrementally drawn. If the system property has any other value,
then the image is not drawn until it has been completely loaded.
Also, if incremental drawing is in effect, the value of the
system property awt.image.redrawrate
is interpreted
as an integer to give the maximum redraw rate, in milliseconds. If
the system property is missing or cannot be interpreted as an
integer, the redraw rate is once every 100ms.
The interpretation of the x
, y
,
width
, and height
arguments depends on
the value of the infoflags
argument.
false
, this Component is
inheriting its background color from an ancestor.false
, this Component is inheriting
its cursor from an ancestor.JFrame
s should have their
Window decorations provided by the current look and feel. This is only
a hint, as certain look and feels may not support this feature.A component is made displayable either when it is added to a displayable containment hierarchy or when its containment hierarchy is made displayable. A containment hierarchy is made displayable when its ancestor window is either packed or made visible.
A component is made undisplayable either when it is removed from a displayable containment hierarchy or when its containment hierarchy is made undisplayable. A containment hierarchy is made undisplayable when its ancestor window is disposed.
setEnabled
method.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.true
because all Windows must be roots of a
focus traversal cycle.true
for both such
Containers in this case.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.
true
if this Component
is the
focus owner.Component
can become the focus
owner.true
then when
keyboard focus manager searches container hierarchy for focus
traversal policy and encounters this container before any other
container with this property as true or focus cycle roots then
its focus traversal policy will be used instead of focus cycle
root's policy.false
, this
Container will inherit its focus traversal policy from an ancestor.false
, this Component is inheriting its
font from an ancestor.false
, this Component is
inheriting its foreground color from an ancestor.Component
and Container
,
other than the ones defined in this package like Button
or Scrollbar
, are lightweight.
All of the Swing components are lightweights.
This method will always return false
if this component
is not displayable because it is impossible to determine the
weight of an undisplayable component.
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.null
value otherwise returns false.setMinimumSize
has been
invoked with a non-null value.An opaque component paints every pixel within its rectangular region. A non-opaque component paints only some of its pixels, allowing the pixels underneath it to "show through". A component that does not fully paint its pixels therefore provides a degree of transparency. Only lightweight components can be transparent.
Subclasses that guarantee to always completely paint their contents should override this method and return true. All of the "heavyweight" AWT components are opaque.
null
value otherwise returns false.Frame
objects.System.out
.
The immediate children of the container are printed with
an indentation of indent+1
. The children
of those children are printed at indent+2
and so on.
The immediate children of the container are printed with
an indentation of indent+1
. The children
of those children are printed at indent+2
and so on.
wait
methods.
The awakened thread will not be able to proceed until the current thread relinquishes the lock on this object. The awakened thread will compete in the usual manner with any other threads that might be actively competing to synchronize on this object; for example, the awakened thread enjoys no reliable privilege or disadvantage in being the next thread to lock this object.
This method should only be called by a thread that is the owner of this object's monitor. A thread becomes the owner of the object's monitor in one of three ways:
synchronized
statement
that synchronizes on the object.
Class,
by executing a
synchronized static method of that class.
Only one thread at a time can own an object's monitor.
wait
methods.
The awakened threads will not be able to proceed until the current thread relinquishes the lock on this object. The awakened threads will compete in the usual manner with any other threads that might be actively competing to synchronize on this object; for example, the awakened threads enjoy no reliable privilege or disadvantage in being the next thread to lock this object.
This method should only be called by a thread that is the owner
of this object's monitor. See the notify
method for a
description of the ways in which a thread can become the owner of
a monitor.
The origin of the graphics context, its
(0
, 0
) coordinate point, is the
top-left corner of this component. The clipping region of the
graphics context is the bounding rectangle of this component.
The image data is downloaded asynchronously in another thread, and an appropriately scaled screen representation of the image is generated.
The origin of the graphics context, its
(0
, 0
) coordinate point, is the
top-left corner of this component. The clipping region of the
graphics context is the bounding rectangle of this component.
comp
is not the rootPane
, this will forward
the call to the contentPane
. This will do nothing if
comp
is not a child of the JFrame
or
contentPane
.index
,
from this container.
This method also notifies the layout manager to remove the
component from this container's layout via the
removeLayoutComponent
method.removeLayoutComponent
method.l
is null
,
no exception is thrown and no action is performed.l
is null
,
no exception is thrown and no action is performed.l
is null
,
no exception is thrown and no action is performed.l
is null
,
no exception is thrown and no action is performed.l
is null
,
no exception is thrown and no action is performed.l
is null
,
no exception is thrown and no action is performed.l
is null
,
no exception is thrown and no action is performed.l
is null
,
no exception is thrown and no action is performed.If listener is null, no exception is thrown and no action is performed.
PropertyChangeListener
from the listener
list for a specific property. This method should be used to remove
PropertyChangeListener
s
that were registered for a specific bound property.
If propertyName
or listener
is null
,
no exception is thrown and no action is taken.
l
is null
, no exception is thrown and
no action is performed.
If this component is a lightweight component, this method
causes a call to this component's paint
method as soon as possible. Otherwise, this method causes
a call to this component's update
method as soon
as possible.
Note: For more information on the paint mechanisms utilitized by AWT and Swing, including information on how to write the most efficient painting code, see Painting in AWT and Swing.
If this component is a lightweight component, this method
causes a call to this component's paint
method
as soon as possible. Otherwise, this method causes a call to
this component's update
method as soon as possible.
Note: For more information on the paint mechanisms utilitized by AWT and Swing, including information on how to write the most efficient painting code, see Painting in AWT and Swing.
paint
within tm
milliseconds.
Note: For more information on the paint mechanisms utilitized by AWT and Swing, including information on how to write the most efficient painting code, see Painting in AWT and Swing.
tm
milliseconds.
If this component is a lightweight component, this method causes
a call to this component's paint
method.
Otherwise, this method causes a call to this component's
update
method.
Note: For more information on the paint mechanisms utilitized by AWT and Swing, including information on how to write the most efficient painting code, see Painting in AWT and Swing.
This method cannot be used to set the focus owner to no Component at
all. Use KeyboardFocusManager.clearGlobalFocusOwner()
instead.
Because the focus behavior of this method is platform-dependent,
developers are strongly encouraged to use
requestFocusInWindow
when possible.
This method returns a boolean value. If false
is returned,
the request is guaranteed to fail. If true
is
returned, the request will succeed unless it is vetoed, or an
extraordinary event, such as disposal of the Component's peer, occurs
before the request can be granted by the native windowing system. Again,
while a return value of true
indicates that the request is
likely to succeed, developers must never assume that this Component is
the focus owner until this Component receives a FOCUS_GAINED event.
This method cannot be used to set the focus owner to no Component at
all. Use KeyboardFocusManager.clearGlobalFocusOwner()
instead.
The focus behavior of this method can be implemented uniformly across
platforms, and thus developers are strongly encouraged to use this
method over requestFocus
when possible. Code which relies
on requestFocus
may exhibit different focus behavior on
different platforms.
If some other window already is always-on-top then the relative order between these windows is unspecified (depends on platform). No window can be brought to be over always-on-top window except maybe another always-on-top window.
All owned windows of an always-on-top window automatically become always-on-top windows. If a window ceases to be always-on-top its owned windows cease to be always-on-top.
When an always-on-top window is sent toBack
its always-on-top state is set to false
.
This method makes the window always-on-top if
alwaysOnTop
is true
. If the window is
visible, this includes bringing window toFront
, then
"sticking" it to the top-most position. If the window is not
visible it does nothing other than setting the always-on-top
property. If later the window is shown, it will be always-on-top.
If the Window is already always-on-top, this call does nothing.
If alwaysOnTop
is false
this
method changes the state from always-on-top to normal. The window
remains top-most but its z-order can be changed in the normal way
as for any other window. Does nothing if this Window is not
always-on-top. Has no effect on relative z-order of windows if
there are no other always-on-top windows.
Note: some platforms might not support always-on-top windows. There is no public API to detect if the platform supports always-on-top at runtime.
If a SecurityManager is installed, the calling thread must be granted the AWTPermission "setWindowAlwaysOnTop" in order to set the value of this property. If this permission is not granted, this method will throw a SecurityException, and the current value of the property will be left unchanged.
The background color affects each component differently and the parts of the component that are affected by the background color may differ between operating systems.
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
LayoutManager
and Component
subclasses will use this property to
determine how to lay out and draw components.
At construction time, a component's orientation is set to
ComponentOrientation.UNKNOWN
,
indicating that it has not been specified
explicitly. The UNKNOWN orientation behaves the same as
ComponentOrientation.LEFT_TO_RIGHT
.
To set the orientation of a single component, use this method. To set the orientation of an entire component hierarchy, use applyComponentOrientation .
If the component is a child of some other container, it is
removed from that container before being added to this container.
The important difference between this method and
java.awt.Container.add(Component, int)
is that this method
doesn't call removeNotify
on the component while
removing it from its previous container unless necessary and when
allowed by the underlying native windowing system. This way, if the
component has the keyboard focus, it maintains the focus when
moved to the new position.
This property is guaranteed to apply only to lightweight
non-Container
components.
Note: Not all platforms support changing the z-order of
heavyweight components from one container into another without
the call to removeNotify
. There is no way to detect
whether a platform supports this, so developers shouldn't make
any assumptions.
The contentPane my not be null.
Generally implemented with
getRootPane().setContentPane(contentPane);
DO_NOTHING_ON_CLOSE
(defined in WindowConstants
):
Don't do anything; require the
program to handle the operation in the windowClosing
method of a registered WindowListener
object.
HIDE_ON_CLOSE
(defined in WindowConstants
):
Automatically hide the frame after
invoking any registered WindowListener
objects.
DISPOSE_ON_CLOSE
(defined in WindowConstants
):
Automatically hide and dispose the
frame after invoking any registered WindowListener
objects.
EXIT_ON_CLOSE
(defined in JFrame
):
Exit the application using the System
exit
method. Use this only in applications.
The value is set to HIDE_ON_CLOSE
by default.
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.
JFrame
s
should have their Window decorations (such as borders, widgets to
close the window, title...) provided by the current look
and feel. If defaultLookAndFeelDecorated
is true,
the current LookAndFeel
supports providing window
decorations, and the current window manager supports undecorated
windows, then newly created JFrame
s will have their
Window decorations provided by the current LookAndFeel
.
Otherwise, newly created JFrame
s will have their
Window decorations provided by the current window manager.
You can get the same effect on a single JFrame by doing the following:
JFrame frame = new JFrame(); frame.setUndecorated(true); frame.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
DropTarget
with this component.
The Component
will receive drops only if it
is enabled.b
. An enabled component can respond to user
input and generate events. Components are enabled initially by default.
Note: Disabling a lightweight component does not prevent it from receiving MouseEvents.
NORMAL
ICONIFIED
MAXIMIZED_HORIZ
MAXIMIZED_VERT
MAXIMIZED_BOTH
MAXIMIZED_HORIZ
and MAXIMIZED_VERT
.
Note that if the state is not supported on a
given platform, nothing will happen. The application
may determine if a specific state is available via
the java.awt.Toolkit#isFrameStateSupported(int state)
method.
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.
The default values for a Container's focus traversal keys are implementation-dependent. Sun recommends that all implementations for a particular native platform use the same default values. The recommendations for Windows and Unix are listed below. These recommendations are used in the Sun AWT implementations.
Identifier | Meaning | Default | |
---|---|---|---|
KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS | Normal forward keyboard traversal | TAB on KEY_PRESSED, CTRL-TAB on KEY_PRESSED | |
KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS | Normal reverse keyboard traversal | SHIFT-TAB on KEY_PRESSED, CTRL-SHIFT-TAB on KEY_PRESSED | |
KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS | Go up one focus traversal cycle | none | |
KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS | Go down one focus traversal cycle | none |
Using the AWTKeyStroke API, client code can specify on which of two specific KeyEvents, KEY_PRESSED or KEY_RELEASED, the focus traversal operation will occur. Regardless of which KeyEvent is specified, however, all KeyEvents related to the focus traversal key, including the associated KEY_TYPED event, will be consumed, and will not be dispatched to any Container. It is a runtime error to specify a KEY_TYPED event as mapping to a focus traversal operation, or to map the same event to multiple default focus traversal operations.
If a value of null is specified for the Set, this Container inherits the Set from its parent. If all ancestors of this Container have null specified for the Set, then the current KeyboardFocusManager's default Set is used.
If this Container is not a focus cycle root, the policy will be remembered, but will not be used or inherited by this or any other Containers until this Container is made a focus cycle root.
true
will be used to acquire focus traversal policy
instead of closest focus cycle root ancestor.The glassPane may not be null.
Generally implemented with
getRootPane().setGlassPane(glassPane);
This is useful, for example, if running under full-screen mode and better performance is desired, or if page-flipping is used as the buffer strategy.
The layeredPane may not be null.
Generally implemented with
getRootPane().setLayeredPane(layeredPane);
LayoutManager
.
Overridden to conditionally forward the call to the
contentPane
.
Refer to javax.swing.RootPaneContainer
for
more information.x
and y
parameters in the coordinate space of this component's parent.p
. Point
p
is given in the parent's coordinate space.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:
The window will be shown at platform's default location andsetLocationByPlatform(true); setVisible(true); boolean flag = isLocationByPlatform();
flag
will be false
.
In the following sample:
The window will be shown at (10, 10) andsetLocationByPlatform(true); setLocation(10, 10); boolean flag = isLocationByPlatform(); setVisible(true);
flag
will be
false
.c
is null
, the
window is centered on the screen. If the bottom of the
component is offscreen, 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 visa versa.When a frame is in maximized state the system supplies some defaults bounds. This method allows some or all of those system supplied values to be overridden.
If bounds
is null
, accept bounds
supplied by the system. If non-null
you can
override some of the system supplied values while accepting
others by setting those fields you want to accept from system
to Integer.MAX_VALUE
.
On some systems only the size portion of the bounds is taken into account.
getMaximumSize
will always
return this value. Setting the maximum size to null
restores the default behavior.getMinimumSize
will always
return this value. Setting the minimum size to null
restores the default behavior.getPreferredSize
will always
return this value. Setting the preferred size to null
restores the default behavior.d.width
and height d.height
.width
and height height
.In older versions of JDK a frame state could only be NORMAL or ICONIFIED. Since JDK 1.4 set of supported frame states is expanded and frame state is represented as a bitwise mask.
For compatibility with old programs this method still accepts
Frame.NORMAL
and Frame.ICONIFIED
but
it only changes the iconic state of the frame, other aspects of
frame state are not affected by this method.
b
.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.
Places this Window at the top of the stacking order and shows it in front of any other Windows in this VM. No action will take place if this Window is not visible. Some platforms do not allow Windows which own other Windows to appear on top of those owned Windows. Some platforms may not permit this VM to place its Windows above windows of native applications, or Windows of other VMs. This permission may depend on whether a Window in this VM is already focused. Every attempt will be made to move this Window as high as possible in the stacking order; however, developers should not assume that this method will move this Window above all other windows in every situation.
Because of variations in native windowing systems, no guarantees about changes to the focused and active Windows can be made. Developers must never assume that this Window is the focused or active Window until this Window receives a WINDOW_GAINED_FOCUS or WINDOW_ACTIVATED event. On platforms where the top-most window is the focused window, this method will probably focus this Window, if it is not already focused. On platforms where the stacking order does not typically affect the focused window, this method will probably leave the focused and active Windows unchanged.
If this method causes this Window to be focused, and this Window is a Frame 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.
paint(g)
. This method was overridden to
prevent an unnecessary call to clear the background.
The validate
method is used to cause a container
to lay out its subcomponents again. It should be invoked when
this container's subcomponents are modified (added to or
removed from the container, or layout-related information
changed) after the container has been displayed.
The current thread must own this object's monitor. The thread
releases ownership of this monitor and waits until another thread
notifies threads waiting on this object's monitor to wake up
either through a call to the notify
method or the
notifyAll
method. The thread then waits until it can
re-obtain ownership of the monitor and resumes execution.
As in the one argument version, interrupts and spurious wakeups are possible, and this method should always be used in a loop:
synchronized (obj) { while (<condition does not hold>) obj.wait(); ... // Perform action appropriate to condition }This method should only be called by a thread that is the owner of this object's monitor. See the
notify
method for a
description of the ways in which a thread can become the owner of
a monitor.The current thread must own this object's monitor.
This method causes the current thread (call it T) to place itself in the wait set for this object and then to relinquish any and all synchronization claims on this object. Thread T becomes disabled for thread scheduling purposes and lies dormant until one of four things happens:
A thread can also wake up without being notified, interrupted, or timing out, a so-called spurious wakeup. While this will rarely occur in practice, applications must guard against it by testing for the condition that should have caused the thread to be awakened, and continuing to wait if the condition is not satisfied. In other words, waits should always occur in loops, like this one:
synchronized (obj) { while (<condition does not hold>) obj.wait(timeout); ... // Perform action appropriate to condition }(For more information on this topic, see Section 3.2.3 in Doug Lea's "Concurrent Programming in Java (Second Edition)" (Addison-Wesley, 2000), or Item 50 in Joshua Bloch's "Effective Java Programming Language Guide" (Addison-Wesley, 2001).
If the current thread is interrupted by another thread while it is waiting, then an InterruptedException is thrown. This exception is not thrown until the lock status of this object has been restored as described above.
Note that the wait method, as it places the current thread into the wait set for this object, unlocks only this object; any other objects on which the current thread may be synchronized remain locked while the thread waits.
This method should only be called by a thread that is the owner
of this object's monitor. See the notify
method for a
description of the ways in which a thread can become the owner of
a monitor.
This method is similar to the wait
method of one
argument, but it allows finer control over the amount of time to
wait for a notification before giving up. The amount of real time,
measured in nanoseconds, is given by:
1000000*timeout+nanos
In all other respects, this method does the same thing as the method of one argument. In particular, wait(0, 0) means the same thing as wait(0).
The current thread must own this object's monitor. The thread releases ownership of this monitor and waits until either of the following two conditions has occurred:
notify
method
or the notifyAll
method.
timeout
milliseconds plus nanos
nanoseconds arguments, has
elapsed.
The thread then waits until it can re-obtain ownership of the monitor and resumes execution.
As in the one argument version, interrupts and spurious wakeups are possible, and this method should always be used in a loop:
synchronized (obj) { while (<condition does not hold>) obj.wait(timeout, nanos); ... // Perform action appropriate to condition }This method should only be called by a thread that is the owner of this object's monitor. See the
notify
method for a
description of the ways in which a thread can become the owner of
a monitor.