Contents | Package | Class | Tree | Deprecated | Index | Help Java 1.2 Beta 3
PREV | NEXT SHOW LISTS | HIDE LISTS

Class java.awt.swing.JFrame

java.lang.Object
    |
    +----java.awt.Component
            |
            +----java.awt.Container
                    |
                    +----java.awt.Window
                            |
                            +----java.awt.Frame
                                    |
                                    +----java.awt.swing.JFrame

public class JFrame
extends Frame
implements WindowConstants, Accessible, RootPaneContainer
An extended version of java.awt.Frame that adds support for interposing input and painting behavior in front of the frames children (see glassPane), support for special children that are managed by a LayeredPane (see rootPane) and for Swing MenuBars.

The JFrame class is slightly incompatible with java.awt.Frame. JFrame contains a JRootPane as it's only child. The contentPane should be the parent of any children of the JFrame. This is different than java.awt.Frame, e.g. to add a child to an AWT Frame you'd write:

       frame.add(child);
 
However using JFrame you need to add the child to the JFrames contentPane instead:
       frame.getContentPane().add(child);
 
The same is true for setting LayoutManagers, removing components, listing children, etc. All these methods should normally be sent to the contentPane() instead of the JFrame itself. The contentPane() will always be non-null. Attempting to set it to null will cause the JFrame to throw an exception. The default contentPane() will have a BorderLayout manager set on it.

Please see the JRootPane documentation for a complete description of the contentPane, glassPane, and layeredPane properties.

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 Swing1.0 applications. It will not be possible to load serialized Swing1.0 objects with future releases of Swing. The JDK1.2 release of Swing will be the compatibility baseline for the serialized form of Swing objects.

See Also:
JRootPane

Inner Class Summary
 JFrame.AccessibleJFrame
 
 

Field Summary
AccessibleContext  accessibleContext
 
JRootPane  rootPane
 
boolean  rootPaneCheckingEnabled
 
 
Fields inherited from class java.awt.Frame
 CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, 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.Component
 BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 

Constructor Summary
 JFrame()
Constructs a new Frame that is initially invisible.
 JFrame(String title)
Constructs a new, initially invisible Frame with the specified title.
 

Method Summary
void  addImpl(Component comp, Object constraints, int index)
By default, children may not be added directly to a this component, they must be added to its contentPane instead.
JRootPane  createRootPane()
Called by the constructor methods to create the default rootPane.
void  frameInit()
Called by the constructors to init the JFrame properly.
AccessibleContext  getAccessibleContext()
Get the AccessibleContext associated with this JFrame
Container  getContentPane()
Returns the contentPane object for this frame.
int  getDefaultCloseOperation()
Returns the operation which occurs when the user initiates a "close" on this frame.
Component  getGlassPane()
Returns the glassPane object for this frame.
JMenuBar  getJMenuBar()
Returns the menubar set on this frame.
JLayeredPane  getLayeredPane()
Returns the layeredPane object for this frame.
JRootPane  getRootPane()
Returns the rootPane object for this frame.
boolean  isRootPaneCheckingEnabled()
 
void  processKeyEvent(KeyEvent e)
 
void  processWindowEvent(WindowEvent e)
 
void  setContentPane(Container contentPane)
Sets the contentPane property.
void  setDefaultCloseOperation(int operation)
Sets the operation which will happen by default when the user initiates a "close" on this frame.
void  setGlassPane(Component glassPane)
Sets the glassPane property.
void  setJMenuBar(JMenuBar menubar)
Sets the menubar for this frame.
void  setLayeredPane(JLayeredPane layeredPane)
Sets the layeredPane property.
void  setLayout(LayoutManager manager)
By default the layout of this component may not be set, the layout of its contentPane should be set instead.
void  setRootPane(JRootPane root)
Sets the rootPane property.
void  setRootPaneCheckingEnabled(boolean enabled)
If true then calls to add() and setLayout() will cause an exception to be thrown.
void  update(Graphics g)
Just calls paint(g).
 
Methods inherited from class java.awt.Frame
 addNotify, dispose, getCursorType, getFrames, getIconImage, getMenuBar, getTitle, isResizable, paramString, remove, setCursor, setIconImage, setMenuBar, setResizable, setTitle
 
Methods inherited from class java.awt.Window
 addNotify, addWindowListener, dispose, getFocusOwner, getInputContext, getLocale, getOwnedWindows, getOwner, getToolkit, getWarningString, isShowing, pack, postEvent, processEvent, processWindowEvent, removeWindowListener, show, toBack, toFront
 
Methods inherited from class java.awt.Container
 add, add, add, add, add, addContainerListener, addImpl, addNotify, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setLayout, update, validate, validateTree
 
Methods inherited from class java.awt.Component
 action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getColorModel, getComponentAt, getComponentAt, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getName, getParent, getPeer, getPreferredSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isDisplayable, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setCursor, setDropTarget, setEnabled, setFont, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, update, validate
 
Methods inherited from class java.lang.Object
 clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rootPane

protected JRootPane rootPane
See Also:
getRootPane, setRootPane

rootPaneCheckingEnabled

protected boolean rootPaneCheckingEnabled
See Also:
isRootPaneCheckingEnabled, setRootPaneCheckingEnabled

accessibleContext

protected AccessibleContext accessibleContext
Constructor Detail

JFrame

public JFrame()
Constructs a new Frame that is initially invisible.
See Also:
setSize, setVisible

JFrame

public JFrame(String title)
Constructs a new, initially invisible Frame with the specified title.
Parameters:
title - the title for the frame
See Also:
setSize, setVisible
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.

processKeyEvent

protected void processKeyEvent(KeyEvent e)
Overrides:
processKeyEvent in class Component

processWindowEvent

protected void processWindowEvent(WindowEvent e)
Overrides:
processWindowEvent in class Window

setDefaultCloseOperation

public void setDefaultCloseOperation(int operation)
Sets the operation which will happen by default when the user initiates a "close" on this frame. The possible choices are:

The value is set to HIDE_ON_CLOSE by default.

See Also:
addWindowListener, getDefaultCloseOperation

getDefaultCloseOperation

public int getDefaultCloseOperation()
Returns the operation which occurs when the user initiates a "close" on this frame.
Returns:
an int indicating the window-close operation
See Also:
setDefaultCloseOperation

update

public void update(Graphics g)
Just calls paint(g). This method was overridden to prevent an unneccessary call to clear the background.
Overrides:
update in class Container

setJMenuBar

public void setJMenuBar(JMenuBar menubar)
Sets the menubar for this frame.
Parameters:
menubar - the menubar being placed in the frame
See Also:
getJMenuBar

getJMenuBar

public JMenuBar getJMenuBar()
Returns the menubar set on this frame.
See Also:
setJMenuBar

isRootPaneCheckingEnabled

protected boolean isRootPaneCheckingEnabled()
Returns:
true if add and setLayout should be checked
See Also:
addImpl, setLayout, setRootPaneCheckingEnabled

setRootPaneCheckingEnabled

protected void setRootPaneCheckingEnabled(boolean enabled)
If true then calls to add() and setLayout() will cause an exception to be thrown.
See Also:
addImpl, setLayout, isRootPaneCheckingEnabled

addImpl

protected void addImpl(Component comp,
                       Object constraints,
                       int index)
By default, children may not be added directly to a 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.
Throws:
Error - if called with rootPaneChecking true
Overrides:
addImpl in class Container
See Also:
setRootPaneCheckingEnabled

setLayout

public void setLayout(LayoutManager manager)
By default the layout of this component may not be set, the layout of its contentPane should be set instead. For example:
 thiComponent.getContentPane().setLayout(new BorderLayout())
 
An attempt to set the layout of this component will cause an runtime exception to be thrown. Subclasses can disable this behavior.
Throws:
Error - if called with rootPaneChecking true
Overrides:
setLayout in class Container
See Also:
setRootPaneCheckingEnabled

getRootPane

public JRootPane getRootPane()
Returns the rootPane object for this frame.
Implements:
getRootPane in interface RootPaneContainer
See Also:
setRootPane, 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, RootPaneContainer#setRootPane

getContentPane

public Container getContentPane()
Returns the contentPane object for this frame.
Implements:
getContentPane in interface RootPaneContainer
See Also:
setContentPane, getContentPane

setContentPane

public void setContentPane(Container contentPane)
Sets the contentPane property. This method is called by the constructor.
Implements:
setContentPane in interface RootPaneContainer
Parameters:
contentPane - the contentPane object for this frame
See Also:
getContentPane, setContentPane

getLayeredPane

public JLayeredPane getLayeredPane()
Returns the layeredPane object for this frame.
Implements:
getLayeredPane in interface RootPaneContainer
See Also:
setLayeredPane, getLayeredPane

setLayeredPane

public void setLayeredPane(JLayeredPane layeredPane)
Sets the layeredPane property. This method is called by the constructor.
Implements:
setLayeredPane in interface RootPaneContainer
Parameters:
layeredPane - the layeredPane object for this frame
See Also:
getLayeredPane, setLayeredPane

getGlassPane

public Component getGlassPane()
Returns the glassPane object for this frame.
Implements:
getGlassPane in interface RootPaneContainer
See Also:
setGlassPane, getGlassPane

setGlassPane

public void setGlassPane(Component glassPane)
Sets the glassPane property. This method is called by the constructor.
Implements:
setGlassPane in interface RootPaneContainer
Parameters:
glassPane - the glassPane object for this frame
See Also:
getGlassPane, setGlassPane

getAccessibleContext

public AccessibleContext getAccessibleContext()
Get the AccessibleContext associated with this JFrame
Implements:
getAccessibleContext in interface Accessible
Returns:
the AccessibleContext of this JFrame

Contents | Package | Class | Tree | Deprecated | Index | Help Java 1.2 Beta 3
PREV | NEXT SHOW LISTS | HIDE LISTS

Submit a bug or feature
Submit comments/suggestions about new javadoc look.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.