Top Description Inners Fields Constructors Methods
java.awt

public Class Frame

extends Window
implements MenuContainer
Class Inheritance
All Implemented Interfaces
java.awt.MenuContainer
Known Direct Subclasses
javax.swing.JFrame, javax.swing.Popup.DefaultFrame, javax.swing.SwingUtilities.SharedOwnerFrame, sun.awt.EmbeddedFrame, sun.awt.LightweightFrame, sun.awt.im.SimpleInputMethodWindow
Imports
java.awt.event.KeyEvent, .WindowEvent, java.awt.peer.FramePeer, java.io.IOException, .ObjectInputStream, .ObjectOutputStream, .Serial, .Serializable, java.util.ArrayList, .Vector, javax.accessibility.AccessibleContext, .AccessibleRole, .AccessibleState, .AccessibleStateSet, sun.awt.AWTAccessor, .SunToolkit

A Frame is a top-level window with a title and a border.

The size of the frame includes any area designated for the border. The dimensions of the border area may be obtained using the getInsets method, however, since these dimensions are platform-dependent, a valid insets value cannot be obtained until the frame is made displayable by either calling pack or show. Since the border area is included in the overall size of the frame, the border effectively obscures a portion of the frame, constraining the area available for rendering and/or displaying subcomponents to the rectangle which has an upper-left corner location of (insets.left, insets.top), and has a size of width - (insets.left + insets.right) by height - (insets.top + insets.bottom).

The default layout for a frame is BorderLayout.

A frame may have its native decorations (i.e. Frame and Titlebar) turned off with setUndecorated. This can only be done while the frame is not displayable.

In a multi-screen environment, you can create a Frame on a different screen device by constructing the Frame with Frame(GraphicsConfiguration) or Frame(String title, 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-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.

Diagram of virtual device
encompassing three physical screens and one primary physical screen. The
primary physical screen shows (0,0) coords while a different physical screen
shows (-80,-100) coords.

In such an environment, when calling setLocation, you must pass a virtual coordinate to this method. Similarly, calling getLocationOnScreen on a Frame 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 the Frame 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 Frame 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.

     Frame f = new Frame(GraphicsConfiguration gc);
     Rectangle bounds = gc.getBounds();
     f.setLocation(10 + bounds.x, 10 + bounds.y);

Frames are capable of generating the following types of WindowEvents:

Author
Sami Shaio
Since
1.0
See Also
WindowEvent, Window#addWindowListener

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class
Frame.AccessibleAWTFrame

This class implements accessibility support for the Frame class.

Field Summary

Modifier and TypeField and Description
private static final String
public static final int
CROSSHAIR_CURSOR

Deprecated replaced by Cursor.CROSSHAIR_CURSOR.
public static final int
DEFAULT_CURSOR

Deprecated replaced by Cursor.DEFAULT_CURSOR.
public static final int
E_RESIZE_CURSOR

Deprecated replaced by Cursor.E_RESIZE_CURSOR.
private int
frameSerializedDataVersion

Frame's Serialized Data Version.

public static final int
HAND_CURSOR

Deprecated replaced by Cursor.HAND_CURSOR.
public static final int
ICONIFIED

This state bit indicates that frame is iconified.

public static final int
MAXIMIZED_BOTH

This state bit mask indicates that frame is fully maximized (that is both horizontally and vertically).

public static final int
MAXIMIZED_HORIZ

This state bit indicates that frame is maximized in the horizontal direction.

public static final int
MAXIMIZED_VERT

This state bit indicates that frame is maximized in the vertical direction.

pack-priv Rectangle
maximizedBounds

Maximized bounds for this frame.

pack-priv boolean
mbManagement

mbManagement is only used by the Motif implementation.

public static final int
MOVE_CURSOR

Deprecated replaced by Cursor.MOVE_CURSOR.
public static final int
N_RESIZE_CURSOR

Deprecated replaced by Cursor.N_RESIZE_CURSOR.
private static int
public static final int
NE_RESIZE_CURSOR

Deprecated replaced by Cursor.NE_RESIZE_CURSOR.
public static final int
NORMAL

Frame is in the "normal" state.

public static final int
NW_RESIZE_CURSOR

Deprecated replaced by Cursor.NW_RESIZE_CURSOR.
pack-priv Vector<Window>
ownedWindows

The Windows owned by the Frame.

pack-priv boolean
resizable

This field indicates whether the frame is resizable.

public static final int
S_RESIZE_CURSOR

Deprecated replaced by Cursor.S_RESIZE_CURSOR.
public static final int
SE_RESIZE_CURSOR

Deprecated replaced by Cursor.SE_RESIZE_CURSOR.
private static final long
serialVersionUID

Hides java.awt.Window.serialVersionUID.

Use serialVersionUID from JDK 1.1 for interoperability.
private int
state

Hides java.awt.Window.state.

The bitwise mask of frame state constants.
public static final int
SW_RESIZE_CURSOR

Deprecated replaced by Cursor.SW_RESIZE_CURSOR.
public static final int
TEXT_CURSOR

Deprecated replaced by Cursor.TEXT_CURSOR.
pack-priv String
title

This is the title of the frame.

pack-priv boolean
undecorated

This field indicates whether the frame is undecorated.

public static final int
W_RESIZE_CURSOR

Deprecated replaced by Cursor.W_RESIZE_CURSOR.
public static final int
WAIT_CURSOR

Deprecated replaced by Cursor.WAIT_CURSOR.
Inherited from java.awt.Window:
anchorbeforeFirstShowdisposerRecordiconsinputContextisInShowisTrayIconWindowmodalBlockermodalExclusionTypeOPENEDownedWindowListshowWithParentsyncLWRequestssystemSyncLWRequestswarningStringwindowFocusListenerwindowListenerwindowStateListener

Constructor Summary

AccessConstructor and Description
public
Frame()

Constructs a new instance of Frame that is initially invisible.

public
Frame(GraphicsConfiguration
the GraphicsConfiguration of the target screen device. If gc is null, the system default GraphicsConfiguration is assumed.
gc
)

Constructs a new, initially invisible Frame with the specified GraphicsConfiguration.

public
Frame(String
the title to be displayed in the frame's border. A null value is treated as an empty string, "".
title
)

Constructs a new, initially invisible Frame object with the specified title.

public
Frame(String
the title to be displayed in the frame's border. A null value is treated as an empty string, "".
title
,
GraphicsConfiguration
the GraphicsConfiguration of the target screen device. If gc is null, the system default GraphicsConfiguration is assumed.
gc
)

Constructs a new, initially invisible Frame object with the specified title and a GraphicsConfiguration.

Method Summary

Modifier and TypeMethod and Description
public void
addNotify()

Overrides java.awt.Window.addNotify.

Makes this Frame displayable by connecting it to a native screen resource.
pack-priv String
constructComponentName()

Overrides java.awt.Window.constructComponentName.

Construct a name for this component.
public AccessibleContext

Returns:

an AccessibleAWTFrame that serves as the AccessibleContext of this Frame
getAccessibleContext
()

Overrides java.awt.Window.getAccessibleContext.

Implements javax.accessibility.Accessible.getAccessibleContext.

Gets the AccessibleContext associated with this Frame.
public int

Returns:

the cursor type for this frame
getCursorType
()

Deprecated As of JDK version 1.1, replaced by Component.getCursor().
public int

Returns:

a bitwise mask of frame state constants
getExtendedState
()

Gets the state of this frame.

public static Frame[]

Returns:

the array of all Frames created by this application
getFrames
()

Returns an array of all Frames created by this application.

public Image

Returns:

the icon image for this frame, or null if this frame doesn't have an icon image.
getIconImage
()

Returns the image to be displayed as the icon for this frame.

public Rectangle

Returns:

maximized bounds for this frame; may be null
getMaximizedBounds
()

Gets maximized bounds for this frame.

public MenuBar

Returns:

the menu bar for this frame, or null if this frame doesn't have a menu bar.
getMenuBar
()

Gets the menu bar for this frame.

public synchronized int

Returns:

Frame.NORMAL or Frame.ICONIFIED.
getState
()

Gets the state of this frame (obsolete).

public String

Returns:

the title of this frame, or an empty string ("") if this frame doesn't have a title.
getTitle
()

Gets the title of the frame.

private void
private static native void
initIDs()

Hides java.awt.Window.initIDs.

Initialize JNI field and method IDs
private boolean
public boolean

Returns:

true if the user can resize this frame; false otherwise.
isResizable
()

Indicates whether this frame is resizable by the user.

public boolean

Returns:

true if frame is undecorated; false otherwise.
isUndecorated
()

Indicates whether this frame is undecorated.

protected String

Returns:

the parameter string of this frame
paramString
()

Overrides java.awt.Container.paramString.

Returns a string representing the state of this Frame.
pack-priv void
private void
readObject(ObjectInputStream
the ObjectInputStream to read
s
)

Hides java.awt.Window.readObject.

Reads the ObjectInputStream.
public void
remove(MenuComponent
the menu component to remove. If m is null, then no action is taken
m
)

Overrides java.awt.Component.remove.

Implements java.awt.MenuContainer.remove.

Removes the specified menu bar from this frame.
public void
removeNotify()

Overrides java.awt.Window.removeNotify.

Makes this Frame undisplayable by removing its connection to its native screen resource.
public void
setBackground(Color
the color to become this window's background color.
bgColor
)

Overrides java.awt.Window.setBackground.

Sets the background color of this window.
public void
setCursor(int
the cursor type
cursorType
)

Deprecated As of JDK version 1.1, replaced by Component.setCursor(Cursor).
Sets the cursor for this frame to the specified type.
public void
setExtendedState(int
a bitwise mask of frame state constants
state
)

Sets the state of this frame.

public void
setIconImage(Image
the icon image to be displayed.
image
)

Overrides java.awt.Window.setIconImage.

Sets the image to be displayed as the icon for this window.
public void
setMaximizedBounds(Rectangle
bounds for the maximized state
bounds
)

Sets the maximized bounds for this frame.

public void
setMenuBar(MenuBar
the menu bar being set. If this parameter is null then any existing menu bar on this frame is removed.
mb
)

Sets the menu bar for this frame to the specified menu bar.

public void
setOpacity(float
the opacity level to set to the window
opacity
)

Overrides java.awt.Window.setOpacity.

Sets the opacity of the window.
public void
setResizable(boolean
true if this frame is resizable; false otherwise.
resizable
)

Sets whether this frame is resizable by the user.

public void
setShape(Shape
the shape to set to the window
shape
)

Overrides java.awt.Window.setShape.

Sets the shape of the window.
public synchronized void
setState(int
either Frame.NORMAL or Frame.ICONIFIED.
state
)

Sets the state of this frame (obsolete).

public void
setTitle(String
the title to be displayed in the frame's border. A null value is treated as an empty string, "".
title
)

Sets the title for this frame to the specified string.

public void
setUndecorated(boolean
true if no frame decorations are to be enabled; false if frame decorations are to be enabled
undecorated
)

Disables or enables decorations for this frame.

private void
writeObject(ObjectOutputStream
the ObjectOutputStream to write
s
)

Hides java.awt.Window.writeObject.

Writes default serializable fields to stream.
Inherited from java.awt.Window:
addOwnedWindowaddPropertyChangeListeneraddPropertyChangeListeneraddWindowFocusListeneraddWindowListeneraddWindowStateListeneradjustDescendantsOnParentadjustListeningChildrenOnParentapplyCompoundShapeapplyCurrentShapeapplyResourceBundleapplyResourceBundlecanContainFocusOwnerclearMostRecentFocusOwnerOnHidecloseSplashScreenconnectOwnedWindowcreateBufferStrategycreateBufferStrategydeliverMouseWheelToAncestordispatchEventImpldispatchMouseWheelToAncestordisposedisposeImpldoDisposeeventEnabledgetAllUnblockedWindowsgetAllWindowsgetBackgroundgetBufferStrategygetContainergetDocumentRootgetFocusableWindowStategetFocusCycleRootAncestorgetFocusOwnergetFocusTraversalKeysgetIconImagesgetInputContextgetListenersgetLocalegetLocationOnWindowgetModalBlockergetModalExclusionTypegetMostRecentFocusOwnergetOpacitygetOwnedWindowsgetOwnedWindows_NoClientCodegetOwnergetOwner_NoClientCodegetOwnerlessWindowsgetShapegetTemporaryLostComponentgetToolkitgetTypegetWarningStringgetWindowFocusListenersgetWindowListenersgetWindowsgetWindowStateListenershideisActiveisAlwaysOnTopisAlwaysOnTopSupportedisAutoRequestFocusisDisposingisFocusableWindowisFocusCycleRootisFocusedisLocationByPlatformisModalBlockedisModalExcludedisOpaqueisRecursivelyVisibleisShowingisValidateRootmixOnReshapingpackpaintpostEventpostWindowEventpreProcessKeyEventprocessEventprocessWindowEventprocessWindowFocusEventprocessWindowStateEventremoveOwnedWindowremoveWindowFocusListenerremoveWindowListenerremoveWindowStateListenerreshapesetAlwaysOnTopsetAutoRequestFocussetBoundssetBoundssetClientSizesetCursorsetFocusableWindowStatesetFocusCycleRootsetGraphicsConfigurationsetIconImagessetLocationsetLocationsetLocationByPlatformsetLocationRelativeTosetMinimumSizesetModalBlockedsetModalExclusionTypesetSizesetSizesetTemporaryLostComponentsetTypesetVisibleshowtoBacktoBack_NoClientCodetoFronttoFront_NoClientCodeupdateChildFocusableWindowStateupdateChildrenBlockingupdateZOrder