Frame

Overview | Package | Class | Use | Tree | Deprecated | Index | Help

PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## java.awt
Class Frame

    java.lang.Object
      java.awt.Component
          java.awt.Container
              java.awt.Window
                  java.awt.Frame

All Implemented Interfaces:
  ImageObserver, Serializable

    public class Frame

extends Window

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.

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 `WindowEvent`s:

- `WINDOW_OPENED`
- `WINDOW_CLOSING`
- `WINDOW_CLOSED`
- `WINDOW_ICONIFIED`
- `WINDOW_DEICONIFIED`
- `WINDOW_ACTIVATED`
- `WINDOW_DEACTIVATED`
- `WINDOW_GAINED_FOCUS`
- `WINDOW_LOST_FOCUS`

#### Clarifications

- The size and location of Frame instances may be severely limited in this profile. Please see the note concerning size and location of `java.awt.Window`.
- Instances of `Frame` are initially created in "windowed" mode. See:
  - `GraphicsDevice.setFullScreenWindow(Window)`
- The decoration, title, and resizability of a `Frame` are under the control of the window management system. Method calls to change these properties are requests (not directives) which are forwarded to the window management system. As a result:
  - The window management system may ignore the decoration of a Frame as reported by `isUndecorated()`. See:
    - `setUndecorated(boolean)`
    - `isUndecorated()`
  - The window management system may ignore the title of a Frame as reported by `getTitle()`. See:
    - `Frame(String)`
    - `Frame(String, GraphicsConfiguration)`
    - `setTitle(java.lang.String)`
    - `getTitle()`
  - The window management system may ignore the resizability of a Frame as reported by `isResizable()`. See:
    - `isResizable()`
    - `setResizable(boolean)`

For more information, see Profile-specific properties.

#### Restrictions

- Only a single instance of `Frame` is permitted per GraphicsDevice. Attempts to construct a second Frame will cause the constructor to throw `java.lang.UnsupportedOperationException`. See:
  - `Frame()`
  - `Frame(GraphicsConfiguration)`
  - `Frame(String)`
  - `Frame(String, GraphicsConfiguration)`
  - `Frame.readObject()`

Since:
  JDK1.0
Version:
  1.139, 01/23/03
Author:
  Sami Shaio
See Also:
  `WindowEvent`, `Window.addWindowListener(java.awt.event.WindowListener)`, Serialized Form

Field Summary
`static int` | `ICONIFIED` This state bit indicates that frame is iconified.
`static int` | `NORMAL` Frame is in the "normal" state.

Fields inherited from class java.awt.Component
`BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT`

Fields inherited from interface java.awt.image.ImageObserver
`ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH`

Constructor Summary
`Frame()` Constructs a new instance of `Frame` that is initially invisible.
`Frame(GraphicsConfiguration gc)` Create a `Frame` with the specified `GraphicsConfiguration` of a screen device.
`Frame(String title)` Constructs a new, initially invisible `Frame` object with the specified title.
`Frame(String title, GraphicsConfiguration gc)` Constructs a new, initially invisible `Frame` object with the specified title and a `GraphicsConfiguration`.

Method Summary
`Image` | `getIconImage()` Gets the image to be displayed in the minimized icon for this frame.
`int` | `getState()` Gets the state of this frame.
`String` | `getTitle()` Gets the title of the frame.
`boolean` | `isResizable()` Indicates whether this frame is resizable by the user.
`boolean` | `isUndecorated()` Indicates whether this frame is undecorated.
`void` | `setIconImage(Image image)` Sets the image to be displayed in the minimized icon for this frame.
`void` | `setResizable(boolean resizable)` Sets whether this frame is resizable by the user.
`void` | `setState(int state)` Sets the state of this frame.
`void` | `setTitle(String title)` Sets the title for this frame to the specified string.
`void` | `setUndecorated(boolean undecorated)` Disables or enables decorations for this frame.

Methods inherited from class java.awt.Window
`addWindowFocusListener, addWindowListener, dispose, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getInputContext, getLocale, getMostRecentFocusOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, isActive, isFocusableWindow, isFocusCycleRoot, isFocused, isShowing, pack, removeWindowFocusListener, removeWindowListener, setCursor, setFocusableWindowState, setFocusCycleRoot, show, toBack, toFront`

Methods inherited from class java.awt.Container
`add, add, add, add, add, addContainerListener, areFocusTraversalKeysSet, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicySet, list, list, paint, paintComponents, print, printComponents, remove, remove, removeAll, removeContainerListener, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, validate`

Methods inherited from class java.awt.Component
`addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enableInputMethods, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getCursor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, hasFocus, imageUpdate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isValid, isVisible, list, list, list, paintAll, prepareImage, prepareImage, printAll, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocusInWindow, setBackground, setBounds, setBounds, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, toString, transferFocus, transferFocusUpCycle`

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### NORMAL

    public static final int NORMAL

  Frame is in the "normal" state. This symbolic constant names a frame state with all state bits cleared.

  See Also:
    Constant Field Values

### ICONIFIED

    public static final int ICONIFIED

  This state bit indicates that frame is iconified.

  See Also:
    Constant Field Values

Constructor Detail

### Frame

    public Frame()
          throws HeadlessException

  Constructs a new instance of `Frame` that is initially invisible. The title of the `Frame` is empty.

  Note: This operation is subject to restriction in Personal Basis Profile.

  Throws:
    `HeadlessException` - when GraphicsEnvironment.isHeadless() returns true
  See Also:
    `GraphicsEnvironment.isHeadless()`, `Component.setSize(int, int)`, `Component.setVisible(boolean)`

### Frame

    public Frame(GraphicsConfiguration gc)

  Create a `Frame` with the specified `GraphicsConfiguration` of a screen device.

  Note: This operation is subject to restriction in Personal Basis Profile.

  Parameters:
    `gc` - the `GraphicsConfiguration` of the target screen device. If `gc` is `null`, the system default `GraphicsConfiguration` is assumed.
  Throws:
    `IllegalArgumentException` - if `gc` is not from a screen device. This exception is always thrown when GraphicsEnvironment.isHeadless() returns true
  Since:
    1.3
  See Also:
    `GraphicsEnvironment.isHeadless()`

### Frame

    public Frame(String title)
          throws HeadlessException

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

  Note: This operation is subject to restriction in Personal Basis Profile.

  Parameters:
    `title` - the title to be displayed in the frame's border. A `null` value is treated as an empty string, "".
  Throws:
    `HeadlessException` - when GraphicsEnvironment.isHeadless() returns true
  See Also:
    `GraphicsEnvironment.isHeadless()`, `Component.setSize(int, int)`, `Component.setVisible(boolean)`, `GraphicsConfiguration.getBounds()`

### Frame

    public Frame(String title,
                 GraphicsConfiguration gc)

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

  Note: This operation is subject to restriction in Personal Basis Profile.

  Parameters:
    `title` - the title to be displayed in the frame's border. A `null` value is treated as an empty string, "".
    `gc` - the `GraphicsConfiguration` of the target screen device. If `gc` is `null`, the system default `GraphicsConfiguration` is assumed.
  Throws:
    `IllegalArgumentException` - if `gc` is not from a screen device. This exception is always thrown when GraphicsEnvironment.isHeadless() returns true
  See Also:
    `GraphicsEnvironment.isHeadless()`, `Component.setSize(int, int)`, `Component.setVisible(boolean)`, `GraphicsConfiguration.getBounds()`

Method Detail

### getTitle

    public String getTitle()

  Gets the title of the frame. The title is displayed in the frame's border.

  Returns:
    the title of this frame, or an empty string ("") if this frame doesn't have a title.
  See Also:
    `setTitle(String)`

### setTitle

    public void setTitle(String title)

  Sets the title for this frame to the specified string.

  Parameters:
    `title` - the title to be displayed in the frame's border. A `null` value is treated as an empty string, "".
  See Also:
    `getTitle()`

### getIconImage

    public Image getIconImage()

  Gets the image to be displayed in the minimized icon for this frame.

  Returns:
    the icon image for this frame, or `null` if this frame doesn't have an icon image.
  See Also:
    `setIconImage(Image)`

### setIconImage

    public void setIconImage(Image image)

  Sets the image to be displayed in the minimized icon for this frame. Not all platforms support the concept of minimizing a window.

  Parameters:
    `image` - the icon image to be displayed. If this parameter is `null` then the icon image is set to the default image, which may vary with platform.
  See Also:
    `getIconImage()`

### isResizable

    public boolean isResizable()

  Indicates whether this frame is resizable by the user. By default, all frames are initially resizable.

  Returns:
    `true` if the user can resize this frame; `false` otherwise.
  See Also:
    `setResizable(boolean)`

### setResizable

    public void setResizable(boolean resizable)

  Sets whether this frame is resizable by the user.

  Parameters:
    `resizable` - `true` if this frame is resizable; `false` otherwise.
  See Also:
    `isResizable()`

### setState

    public void setState(int state)

  Sets the state of this frame.

  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 `Toolkit.isFrameStateSupported(int state)`.

  Parameters:
    `state` - either `Frame.NORMAL` or `Frame.ICONIFIED`.
  See Also:
    `getState()`

### getState

    public int getState()

  Gets the state of this frame.

  Returns:
    `Frame.NORMAL` or `Frame.ICONIFIED`.
  See Also:
    `setState(int)`

### setUndecorated

    public void setUndecorated(boolean undecorated)

  Disables or enables decorations for this frame. This method can only be called while the frame is not displayable.

  Parameters:
    `undecorated` - `true` if no frame decorations are to be enabled; `false` if frame decorations are to be enabled.
  Throws:
    ``IllegalComponentStateException`` - if the frame is displayable.
  Since:
    1.4
  See Also:
    `isUndecorated()`, `Component.isDisplayable()`

### isUndecorated

    public boolean isUndecorated()

  Indicates whether this frame is undecorated.

  Returns:
    `true` if frame is undecorated; `false` otherwise.
  Since:
    1.4
  See Also:
    `setUndecorated(boolean)`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help

PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD