javax.swing
Class JFrame

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Window
                    |
                    +--java.awt.Frame
                          |
                          +--javax.swing.JFrame
All Implemented Interfaces:
Accessible, java.awt.image.ImageObserver, MenuContainer, RootPaneContainer, Serializable, WindowConstants
Direct Known Subclasses:
ASTFrame

public class JFrame
extends Frame
implements WindowConstants, Accessible, RootPaneContainer

Unsafe:

See Also:
Serialized Form

Field Summary
protected  AccessibleContext accessibleContext
          The accessible context property.
private  int defaultCloseOperation
           
private static Object defaultLookAndFeelDecoratedKey
          Key into the AppContext, used to check if should provide decorations by default.
static int EXIT_ON_CLOSE
          Enabled: The exit application default window close operation.
protected  JRootPane rootPane
          The JRootPane instance that manages the contentPane and optional menuBar for this frame, as well as the glassPane.
protected  boolean rootPaneCheckingEnabled
          If true then calls to add and setLayout will cause an exception to be thrown.
 
Fields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
 
Fields inherited from class java.awt.Window
 
Fields inherited from class java.awt.Container
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE
 
Constructor Summary
JFrame()
          Enabled: Constructs a new frame that is initially invisible.
JFrame(GraphicsConfiguration gc)
          Suppressed: Creates a Frame in the specified GraphicsConfiguration of a screen device and a blank title.
JFrame(String title)
          Enabled: Creates a new, initially invisible Frame with the specified title.
JFrame(String title, GraphicsConfiguration gc)
          Enabled: Creates a JFrame with the specified title and the specified GraphicsConfiguration of a screen device.
 
Method Summary
protected  void addImpl(Component comp, Object constraints, int index)
          By default, children may not be added directly to this component, they must be added to its contentPane instead.
protected  JRootPane createRootPane()
          Called by the constructor methods to create the default rootPane.
private  Error createRootPaneException(String op)
          Creates a runtime exception with a message like:
protected  void frameInit()
          Called by the constructors to init the JFrame properly.
 AccessibleContext getAccessibleContext()
          Suppressed: Gets the AccessibleContext associated with this JFrame.
 Container getContentPane()
          Enabled: Returns the contentPane object for this frame.
 int getDefaultCloseOperation()
          Enabled: Returns the operation that occurs when the user initiates a "close" on this frame.
 Component getGlassPane()
          Suppressed: Returns the glassPane object for this frame.
 JMenuBar getJMenuBar()
          Enabled: Returns the menubar set on this frame.
 JLayeredPane getLayeredPane()
          Suppressed: Returns the layeredPane object for this frame.
 JRootPane getRootPane()
          Suppressed: Returns the rootPane object for this frame.
static boolean isDefaultLookAndFeelDecorated()
          Suppressed: Returns true if newly created JFrames should have their Window decorations provided by the current look and feel.
protected  boolean isRootPaneCheckingEnabled()
          Returns whether calls to add and setLayout cause an exception to be thrown.
protected  String paramString()
          Returns a string representation of this JFrame.
protected  void processWindowEvent(WindowEvent e)
          Processes window events occurring on this component.
 void remove(Component comp)
          Enabled: Removes the specified component from this container.
 void setContentPane(Container contentPane)
          Enabled: Sets the contentPane property.
 void setDefaultCloseOperation(int operation)
          Enabled: Sets the operation that will happen by default when the user initiates a "close" on this frame.
static void setDefaultLookAndFeelDecorated(boolean defaultLookAndFeelDecorated)
          Suppressed: Provides a hint as to whether or not newly created JFrames should have their Window decorations (such as borders, widgets to close the window, title...) provided by the current look and feel.
 void setGlassPane(Component glassPane)
          Suppressed: Sets the glassPane property.
 void setJMenuBar(JMenuBar menubar)
          Enabled: Sets the menubar for this frame.
 void setLayeredPane(JLayeredPane layeredPane)
          Suppressed: Sets the layeredPane property.
 void setLayout(LayoutManager manager)
          Enabled: By default the layout of this component may not be set, the layout of its contentPane should be set instead.
protected  void setRootPane(JRootPane root)
          Sets the rootPane property.
protected  void setRootPaneCheckingEnabled(boolean enabled)
          Determines whether calls to add and setLayout will cause an exception to be thrown.
 void update(Graphics g)
          Enabled: Just calls paint(g).
 
Methods inherited from class java.awt.Frame
addNotify, finalize, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setIconImage, setMaximizedBounds, setMenuBar, setResizable, setState, setTitle, setUndecorated
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, hide, isActive, isFocusableWindow, isFocusCycleRoot, isFocused, isShowing, pack, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationRelativeTo, show, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, get, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicySet, iterate, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, size, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.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, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, 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, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, toString, transferFocus, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Field Detail

EXIT_ON_CLOSE

public static final int EXIT_ON_CLOSE
Enabled: The exit application default window close operation. If a window has this set as the close operation and is closed in an applet, a SecurityException may be thrown. It is recommended you only use this in an application.

Since:
1.3

defaultLookAndFeelDecoratedKey

private static final Object defaultLookAndFeelDecoratedKey
Key into the AppContext, used to check if should provide decorations by default.


defaultCloseOperation

private int defaultCloseOperation

rootPane

protected JRootPane rootPane
The JRootPane instance that manages the contentPane and optional menuBar for this frame, as well as the glassPane.

See Also:
JRootPane, RootPaneContainer

rootPaneCheckingEnabled

protected boolean rootPaneCheckingEnabled
If true then calls to add and setLayout will cause an exception to be thrown. The default is false.

See Also:
isRootPaneCheckingEnabled(), setRootPaneCheckingEnabled(boolean)

accessibleContext

protected AccessibleContext accessibleContext
The accessible context property.

Constructor Detail

JFrame

public JFrame()
       throws HeadlessException
Enabled: Constructs a new frame that is initially invisible.

This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale.

See Also:
java.awt.GraphicsEnvironment#isHeadless, Component.setSize(int, int), Component.setVisible(boolean), JComponent.getDefaultLocale()

JFrame

public JFrame(GraphicsConfiguration gc)
Suppressed: Creates a 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.

Parameters:
gc - the GraphicsConfiguration that is used to construct the new Frame; if gc is null, the system default GraphicsConfiguration is assumed
Since:
1.3
See Also:
java.awt.GraphicsEnvironment#isHeadless, JComponent.getDefaultLocale()

JFrame

public JFrame(String title)
       throws HeadlessException
Enabled: Creates a new, initially invisible Frame with the specified title.

This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale.

Parameters:
title - the title for the frame
See Also:
java.awt.GraphicsEnvironment#isHeadless, Component.setSize(int, int), Component.setVisible(boolean), JComponent.getDefaultLocale()

JFrame

public JFrame(String title,
              GraphicsConfiguration gc)
Enabled: Creates a 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.

Parameters:
title - the title to be displayed in the frame's border. A null value is treated as an empty string, "".
gc - the GraphicsConfiguration that is used to construct the new JFrame with; if gc is null, the system default GraphicsConfiguration is assumed
Since:
1.3
See Also:
java.awt.GraphicsEnvironment#isHeadless, JComponent.getDefaultLocale()
Method Detail

frameInit

protected void frameInit()
Called by the constructors to init the JFrame properly.


createRootPane

protected JRootPane createRootPane()
Called by the constructor methods to create the default rootPane.


processWindowEvent

protected void processWindowEvent(WindowEvent e)
Processes window events occurring on this component. Hides the window or disposes of it, as specified by the setting of the defaultCloseOperation property.

Overrides:
processWindowEvent in class Window
Parameters:
e - the window event
See Also:
setDefaultCloseOperation(int), java.awt.Window#processWindowEvent

setDefaultCloseOperation

public void setDefaultCloseOperation(int operation)
Enabled: Sets the operation that will happen by default when the user initiates a "close" on this frame. You must specify one of the following choices:

The value is set to HIDE_ON_CLOSE by default.

Parameters:
operation - the operation which should be performed when the user closes the frame
Throws:
SecurityException - If EXIT_ON_CLOSE has been specified and the SecurityManager will not allow the caller to invoke System.exit.
See Also:
Window.addWindowListener(java.awt.event.WindowListener), getDefaultCloseOperation(), WindowConstants, java.lang.Runtime#exit(int)

getDefaultCloseOperation

public int getDefaultCloseOperation()
Enabled: Returns the operation that occurs when the user initiates a "close" on this frame.

Returns:
an integer indicating the window-close operation
See Also:
setDefaultCloseOperation(int)

update

public void update(Graphics g)
Enabled: Just calls paint(g). This method was overridden to prevent an unnecessary call to clear the background.

Overrides:
update in class Container
Parameters:
g - the Graphics context in which to paint
See Also:
Component.update(Graphics)

setJMenuBar

public void setJMenuBar(JMenuBar menubar)
Enabled: Sets the menubar for this frame.

Parameters:
menubar - the menubar being placed in the frame
See Also:
getJMenuBar()

getJMenuBar

public JMenuBar getJMenuBar()
Enabled: Returns the menubar set on this frame.

Returns:
the menubar for this frame
See Also:
setJMenuBar(javax.swing.JMenuBar)

isRootPaneCheckingEnabled

protected boolean isRootPaneCheckingEnabled()
Returns whether calls to add and setLayout cause an exception to be thrown.

Returns:
true if add and setLayout are checked; false otherwise
See Also:
addImpl(java.awt.Component, java.lang.Object, int), setLayout(java.awt.LayoutManager), setRootPaneCheckingEnabled(boolean)

setRootPaneCheckingEnabled

protected void setRootPaneCheckingEnabled(boolean enabled)
Determines whether calls to add and setLayout will cause an exception to be thrown.

Parameters:
enabled - true if checking is to be enabled, which causes the exceptions to be thrown
See Also:
addImpl(java.awt.Component, java.lang.Object, int), setLayout(java.awt.LayoutManager), isRootPaneCheckingEnabled()

createRootPaneException

private Error createRootPaneException(String op)
Creates a runtime exception with a message like:
 "Do not use JFrame.add() use JFrame.getContentPane().add() instead"
 

Parameters:
op - a String indicating the attempted operation; in the example above, the operation string is "add"

addImpl

protected void addImpl(Component comp,
                       Object constraints,
                       int index)
By default, children may not be added directly to this component, they must be added to its contentPane instead. For example:
 thisComponent.getContentPane().add(child)
 
An attempt to add to directly to this component will cause an runtime exception to be thrown. Subclasses can disable this behavior.

Overrides:
addImpl in class Container
Parameters:
comp - the component to be enhanced
constraints - the constraints to be respected
index - the index
See Also:
setRootPaneCheckingEnabled(boolean)

remove

public void remove(Component comp)
Enabled: Removes the specified component from this container.

Overrides:
remove in class Container
Parameters:
comp - the component to be removed
See Also:
Container.add(java.awt.Component)

setLayout

public void setLayout(LayoutManager manager)
Enabled: By default the layout of this component may not be set, the layout of its contentPane should be set instead. For example:
 thisComponent.getContentPane().setLayout(new GridLayout(1, 2))
 
An attempt to set the layout of this component will cause an runtime exception to be thrown. Subclasses can disable this behavior.

Overrides:
setLayout in class Container
Parameters:
manager - the LayoutManager
See Also:
setRootPaneCheckingEnabled(boolean)

getRootPane

public JRootPane getRootPane()
Suppressed: Returns the rootPane object for this frame.

Specified by:
getRootPane in interface RootPaneContainer
Returns:
the rootPane property
See Also:
setRootPane(javax.swing.JRootPane), RootPaneContainer.getRootPane()

setRootPane

protected void setRootPane(JRootPane root)
Sets the rootPane property. This method is called by the constructor.

Parameters:
root - the rootPane object for this frame
See Also:
getRootPane()

getContentPane

public Container getContentPane()
Enabled: Returns the contentPane object for this frame.

Specified by:
getContentPane in interface RootPaneContainer
Returns:
the contentPane property
See Also:
setContentPane(java.awt.Container), RootPaneContainer.getContentPane()

setContentPane

public void setContentPane(Container contentPane)
Enabled: Sets the contentPane property. This method is called by the constructor.

Swing's painting architecture requires an opaque JComponent in the containment hiearchy. This is typically provided by the content pane. If you replace the content pane it is recommended you replace it with an opaque JComponent.

Specified by:
setContentPane in interface RootPaneContainer
Parameters:
contentPane - the contentPane object for this frame
See Also:
getContentPane(), RootPaneContainer.setContentPane(java.awt.Container), JRootPane

getLayeredPane

public JLayeredPane getLayeredPane()
Suppressed: Returns the layeredPane object for this frame.

Specified by:
getLayeredPane in interface RootPaneContainer
Returns:
the layeredPane property
See Also:
setLayeredPane(javax.swing.JLayeredPane), RootPaneContainer.getLayeredPane()

setLayeredPane

public void setLayeredPane(JLayeredPane layeredPane)
Suppressed: Sets the layeredPane property. This method is called by the constructor.

Specified by:
setLayeredPane in interface RootPaneContainer
Parameters:
layeredPane - the layeredPane object for this frame
See Also:
getLayeredPane(), RootPaneContainer.setLayeredPane(javax.swing.JLayeredPane)

getGlassPane

public Component getGlassPane()
Suppressed: Returns the glassPane object for this frame.

Specified by:
getGlassPane in interface RootPaneContainer
Returns:
the glassPane property
See Also:
setGlassPane(java.awt.Component), RootPaneContainer.getGlassPane()

setGlassPane

public void setGlassPane(Component glassPane)
Suppressed: Sets the glassPane property. This method is called by the constructor.

Specified by:
setGlassPane in interface RootPaneContainer
Parameters:
glassPane - the glassPane object for this frame
See Also:
getGlassPane(), RootPaneContainer.setGlassPane(java.awt.Component)

setDefaultLookAndFeelDecorated

public static void setDefaultLookAndFeelDecorated(boolean defaultLookAndFeelDecorated)
Suppressed: Provides a hint as to whether or not newly created JFrames 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 JFrames will have their Window decorations provided by the current LookAndFeel. Otherwise, newly created JFrames 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);
 

Parameters:
defaultLookAndFeelDecorated - A hint as to whether or not current look and feel should provide window decorations
Since:
1.4
See Also:
javax.swing.LookAndFeel#getSupportsWindowDecorations

isDefaultLookAndFeelDecorated

public static boolean isDefaultLookAndFeelDecorated()
Suppressed: Returns true if newly created JFrames 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.

Returns:
true if look and feel should provide Window decorations.
Since:
1.4

paramString

protected String paramString()
Returns a string representation of this JFrame. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null.

Overrides:
paramString in class Frame
Returns:
a string representation of this JFrame

getAccessibleContext

public AccessibleContext getAccessibleContext()
Suppressed: Gets the AccessibleContext associated with this JFrame. For JFrames, the AccessibleContext takes the form of an AccessibleJFrame. A new AccessibleJFrame instance is created if necessary.

Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in class Frame
Returns:
an AccessibleJFrame that serves as the AccessibleContext of this JFrame


comments?