All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.sun.java.swing.JFrame

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Container
                   |
                   +----java.awt.Window
                           |
                           +----java.awt.Frame
                                   |
                                   +----com.sun.java.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

Variable Index

 o accessibleContext
 o rootPane
 o rootPaneCheckingEnabled

Constructor Index

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

Method Index

 o addImpl(Component, Object, int)
By default, children may not be added directly to a this component, they must be added to its contentPane instead.
 o createRootPane()
Called by the constructor methods to create the default rootPane.
 o frameInit()
Called by the constructors to init the JFrame properly.
 o getAccessibleContext()
Get the AccessibleContext associated with this JFrame
 o getContentPane()
Returns the contentPane object for this frame.
 o getDefaultCloseOperation()
Returns the operation which occurs when the user initiates a "close" on this frame.
 o getGlassPane()
Returns the glassPane object for this frame.
 o getJMenuBar()
Returns the menubar set on this frame.
 o getLayeredPane()
Returns the layeredPane object for this frame.
 o getRootPane()
Returns the rootPane object for this frame.
 o isRootPaneCheckingEnabled()
 o processKeyEvent(KeyEvent)
 o processWindowEvent(WindowEvent)
 o setContentPane(Container)
Sets the contentPane property.
 o setDefaultCloseOperation(int)
Sets the operation which will happen by default when the user initiates a "close" on this frame.
 o setGlassPane(Component)
Sets the glassPane property.
 o setJMenuBar(JMenuBar)
Sets the menubar for this frame.
 o setLayeredPane(JLayeredPane)
Sets the layeredPane property.
 o setLayout(LayoutManager)
By default the layout of this component may not be set, the layout of its contentPane should be set instead.
 o setRootPane(JRootPane)
Sets the rootPane property.
 o setRootPaneCheckingEnabled(boolean)
If true then calls to add() and setLayout() will cause an exception to be thrown.
 o update(Graphics)
Just calls paint(g).

Variables

 o rootPane
 protected JRootPane rootPane
See Also:
getRootPane, setRootPane
 o rootPaneCheckingEnabled
 protected boolean rootPaneCheckingEnabled
See Also:
isRootPaneCheckingEnabled, setRootPaneCheckingEnabled
 o accessibleContext
 protected AccessibleContext accessibleContext

Constructors

 o JFrame
 public JFrame()
Constructs a new Frame that is initially invisible.

See Also:
setSize, setVisible
 o 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

Methods

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

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

 o processKeyEvent
 protected void processKeyEvent(KeyEvent e)
Overrides:
processKeyEvent in class Component
 o processWindowEvent
 protected void processWindowEvent(WindowEvent e)
Overrides:
processWindowEvent in class Window
 o 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
 o 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
 o 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
 o setJMenuBar
 public void setJMenuBar(JMenuBar menubar)
Sets the menubar for this frame.

Parameters:
menubar - the menubar being placed in the frame
See Also:
getJMenuBar
 o getJMenuBar
 public JMenuBar getJMenuBar()
Returns the menubar set on this frame.

See Also:
setJMenuBar
 o isRootPaneCheckingEnabled
 protected boolean isRootPaneCheckingEnabled()
Returns:
true if add and setLayout should be checked
See Also:
addImpl, setLayout, setRootPaneCheckingEnabled
 o 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
 o 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
 o 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
 o getRootPane
 public JRootPane getRootPane()
Returns the rootPane object for this frame.

See Also:
setRootPane, getRootPane
 o 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, setRootPane
 o getContentPane
 public Container getContentPane()
Returns the contentPane object for this frame.

See Also:
setContentPane, getContentPane
 o setContentPane
 public void setContentPane(Container contentPane)
Sets the contentPane property. This method is called by the constructor.

Parameters:
contentPane - the contentPane object for this frame
See Also:
getContentPane, setContentPane
 o getLayeredPane
 public JLayeredPane getLayeredPane()
Returns the layeredPane object for this frame.

See Also:
setLayeredPane, getLayeredPane
 o setLayeredPane
 public void setLayeredPane(JLayeredPane layeredPane)
Sets the layeredPane property. This method is called by the constructor.

Parameters:
layeredPane - the layeredPane object for this frame
See Also:
getLayeredPane, setLayeredPane
 o getGlassPane
 public Component getGlassPane()
Returns the glassPane object for this frame.

See Also:
setGlassPane, getGlassPane
 o setGlassPane
 public void setGlassPane(Component glassPane)
Sets the glassPane property. This method is called by the constructor.

Parameters:
glassPane - the glassPane object for this frame
See Also:
getGlassPane, setGlassPane
 o getAccessibleContext
 public AccessibleContext getAccessibleContext()
Get the AccessibleContext associated with this JFrame

Returns:
the AccessibleContext of this JFrame

All Packages  Class Hierarchy  This Package  Previous  Next  Index