java.awt.Frame
that adds support for
the JFC/Swing component architecture.
You can find task-oriented documentation about using JFrame
in The Java Tutorial, in the section
How to Make Frames.
The JFrame
class is slightly incompatible with Frame
.
Like all other JFC/Swing top-level containers,
a JFrame
contains a JRootPane
as its only child.
The content pane provided by the root pane should,
as a rule, contain
all the non-menu components displayed by the JFrame
.
This is different from the AWT Frame
case.
As a convenience, the add
, remove
, and setLayout
methods of this class are overridden, so that they delegate calls
to the corresponding methods of the ContentPane
.
For example, you can add a child component to a frame as follows:
frame.add(child);And the child will be added to the contentPane. The content pane will always be non-null. Attempting to set it to null will cause the JFrame to throw an exception. The default content pane will have a BorderLayout manager set on it. Refer to
javax.swing.RootPaneContainer
for details on adding, removing and setting the LayoutManager
of a JFrame
.
Unlike a Frame
, a JFrame
has some notion of how to
respond when the user attempts to close the window. The default behavior
is to simply hide the JFrame when the user closes the window. To change the
default behavior, you invoke the method
setDefaultCloseOperation
.
To make the JFrame
behave the same as a Frame
instance, use
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE)
.
For more information on content panes and other features that root panes provide, see Using Top-Level Containers in The Java Tutorial.
In a multi-screen environment, you can create a JFrame
on a different screen device. See java.
for more
information.
Warning
Swing is not thread safe. For more information see Swing's Threading Policy.
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 applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeans
has been added to the java.beans
package.
Please see java.
.
JRootPane
, setDefaultCloseOperation
, java.awt.event.WindowListener#windowClosing
, javax.swing.RootPaneContainer
Modifier and Type | Class and Description |
---|---|
protected class | JFrame.
This class implements accessibility support for the
|
Modifier and Type | Field and Description |
---|---|
protected AccessibleContext | accessibleContext
The accessible context property.
|
private int | |
private static final Object | defaultLookAndFeelDecoratedKey
Key into the AppContext, used to check if should provide decorations by default. |
protected JRootPane | rootPane
The |
protected boolean | rootPaneCheckingEnabled
If true then calls to |
private TransferHandler | transferHandler
The |
Access | Constructor and Description |
---|---|
public | |
public | JFrame(GraphicsConfiguration
the gc)GraphicsConfiguration that is used
to construct the new Frame ;
if gc is null , the system
default GraphicsConfiguration is assumedCreates a |
public | |
public | JFrame(String
the title to be displayed in the
frame's border. A title, GraphicsConfiguration null value is treated as
an empty string, "".the gc)GraphicsConfiguration that is used
to construct the new JFrame with;
if gc is null , the system
default GraphicsConfiguration is assumedCreates a |
Modifier and Type | Method and Description |
---|---|
protected void | addImpl(Component
the component to be enhanced comp, Object the constraints to be respected constraints, int the index index)Overrides java. Component .
|
protected JRootPane | Returns: a newJRootPane Called by the constructor methods to create the default
|
protected void | |
public AccessibleContext | Returns: an AccessibleJFrame that serves as the AccessibleContext of this JFrameOverrides java. Implements javax. |
public Container | Returns: thecontentPane propertyImplements javax. contentPane object for this frame.
|
public int | Returns: an integer indicating the window-close operationReturns the operation that occurs when the user initiates a "close" on this frame. |
public Component | Returns: theglassPane propertyImplements javax. glassPane object for this frame.
|
public Graphics | getGraphics()
Overrides java. |
public JMenuBar | |
public JLayeredPane | Returns: thelayeredPane propertyImplements javax. layeredPane object for this frame.
|
public JRootPane | Returns: therootPane propertyImplements javax. rootPane object for this frame.
|
public TransferHandler | Returns: the value of thetransferHandler propertyImplements javax. transferHandler property.
|
public static boolean | Returns: true if look and feel should provide Window decorations.Returns true if newly created |
protected boolean | Returns: true ifadd and setLayout
are forwarded; false otherwiseReturns whether calls to |
protected String | Returns: a string representation of thisJFrame Overrides java. JFrame .
|
protected void | processWindowEvent(final WindowEvent
the window event e)Overrides java. |
public void | remove(Component
the component to be removed comp)Overrides java. |
public void | repaint(long
maximum time in milliseconds before update time, int the x coordinate x, int the y coordinate y, int the width width, int the height height)Overrides java. time milliseconds.
|
public void | setContentPane(Container
the contentPane)contentPane object for this frameImplements javax. contentPane property.
|
public void | setDefaultCloseOperation(int
the operation which should be performed when the
user closes the frame operation)Sets the operation that will happen by default when the user initiates a "close" on this frame. |
public static void | setDefaultLookAndFeelDecorated(boolean
A hint as to whether or not current
look and feel should provide window decorations defaultLookAndFeelDecorated)Provides a hint as to whether or not newly created |
public void | setGlassPane(Component
the glassPane)glassPane object for this frameImplements javax. glassPane property.
|
public void | setIconImage(Image
the icon image to be displayed. image)Overrides java. |
public void | setJMenuBar(final JMenuBar
the menubar being placed in the frame menubar)Sets the menubar for this frame. |
public void | setLayeredPane(JLayeredPane
the layeredPane)layeredPane object for this frameImplements javax. layeredPane property.
|
public void | setLayout(LayoutManager
the manager)LayoutManager Overrides java. LayoutManager .
|
protected void | |
protected void | setRootPaneCheckingEnabled(boolean
true if enabled)add and setLayout
are forwarded, false if they should operate directly on the
JFrame .Sets whether calls to |
public void | setTransferHandler(TransferHandler
the new newHandler)TransferHandler Sets the |
public void | update(Graphics
the Graphics context in which to paint g)Overrides java. paint(g) .
|
accessibleContext | back to summary |
---|---|
protected AccessibleContext accessibleContext Hides java. The accessible context property. |
defaultCloseOperation | back to summary |
---|---|
private int defaultCloseOperation |
defaultLookAndFeelDecoratedKey | back to summary |
---|---|
private static final Object defaultLookAndFeelDecoratedKey Key into the AppContext, used to check if should provide decorations by default. |
rootPane | back to summary |
---|---|
protected JRootPane rootPane The
|
rootPaneCheckingEnabled | back to summary |
---|---|
protected boolean rootPaneCheckingEnabled If true then calls to |
transferHandler | back to summary |
---|---|
private TransferHandler transferHandler The |
JFrame | back to summary |
---|---|
public JFrame() throws HeadlessException Constructs a new frame that is initially invisible.
This constructor sets the component's locale property to the value
returned by
|
JFrame | back to summary |
---|---|
public JFrame(GraphicsConfiguration gc) Creates a
This constructor sets the component's locale property to the value
returned by
|
JFrame | back to summary |
---|---|
public JFrame(String title) throws HeadlessException Creates a new, initially invisible
This constructor sets the component's locale property to the value
returned by
|
JFrame | back to summary |
---|---|
public JFrame(String title, GraphicsConfiguration gc) Creates a
This constructor sets the component's locale property to the value
returned by
|
addImpl | back to summary |
---|---|
protected void addImpl(Component comp, Object constraints, int index) Overrides java. Adds the specified child
|
createRootPane | back to summary |
---|---|
protected JRootPane createRootPane() Called by the constructor methods to create the default
|
frameInit | back to summary |
---|---|
protected void frameInit() Called by the constructors to init the |
getAccessibleContext | back to summary |
---|---|
public AccessibleContext getAccessibleContext() Overrides java. Implements javax. 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.
|
getContentPane | back to summary |
---|---|
public Container getContentPane() Implements javax. Returns the
|
getDefaultCloseOperation | back to summary |
---|---|
public int getDefaultCloseOperation() Returns the operation that occurs when the user initiates a "close" on this frame.
|
getGlassPane | back to summary |
---|---|
public Component getGlassPane() Implements javax. Returns the
|
getGraphics | back to summary |
---|---|
public Graphics getGraphics() Overrides java. Doc from java. Creates a graphics context for this component. This method will
return
|
getJMenuBar | back to summary |
---|---|
public JMenuBar getJMenuBar() Returns the menubar set on this frame.
|
getLayeredPane | back to summary |
---|---|
public JLayeredPane getLayeredPane() Implements javax. Returns the
|
getRootPane | back to summary |
---|---|
public JRootPane getRootPane() Implements javax. Returns the
|
getTransferHandler | back to summary |
---|---|
public TransferHandler getTransferHandler() Implements javax. Gets the
|
isDefaultLookAndFeelDecorated | back to summary |
---|---|
public static boolean isDefaultLookAndFeelDecorated() Returns true if newly created
|
isRootPaneCheckingEnabled | back to summary |
---|---|
protected boolean isRootPaneCheckingEnabled() Returns whether calls to
|
paramString | back to summary |
---|---|
protected String paramString() Overrides java. Returns a string representation of this
|
processWindowEvent | back to summary |
---|---|
protected void processWindowEvent(final WindowEvent e) Overrides java. Processes window events occurring on this component.
Hides the window or disposes of it, as specified by the setting
of the
|
remove | back to summary |
---|---|
public void remove(Component comp) Overrides java. Removes the specified component from the container. If
|
repaint | back to summary |
---|---|
public void repaint(long time, int x, int y, int width, int height) Overrides java. Repaints the specified rectangle of this component within
|
setContentPane | back to summary |
---|---|
public void setContentPane(Container contentPane) Implements javax. Sets the
Swing's painting architecture requires an opaque
|
setDefaultCloseOperation | back to summary |
---|---|
public void setDefaultCloseOperation(int operation) 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 Note When the last displayable window within the Java virtual machine (VM) is disposed of, the VM may terminate. See AWT Threading Issues for more information.
|
setDefaultLookAndFeelDecorated | back to summary |
---|---|
public static void setDefaultLookAndFeelDecorated(boolean defaultLookAndFeelDecorated) Provides a hint as to whether or not newly created 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);
|
setGlassPane | back to summary |
---|---|
public void setGlassPane(Component glassPane) Implements javax. Sets the
|
setIconImage | back to summary |
---|---|
public void setIconImage(Image image) Overrides java. Doc from java. Sets the image to be displayed as the icon for this window.
This method can be used instead of The following statement: setIconImage(image);is equivalent to: ArrayList<Image> imageList = new ArrayList<Image>(); imageList.add(image); setIconImages(imageList); Note : Native windowing systems may use different images of differing dimensions to represent a window, depending on the context (e.g. window decoration, window list, taskbar, etc.). They could also use just a single image for all contexts or no image at all.
|
setJMenuBar | back to summary |
---|---|
public void setJMenuBar(final JMenuBar menubar) Sets the menubar for this frame.
|
setLayeredPane | back to summary |
---|---|
public void setLayeredPane(JLayeredPane layeredPane) Implements javax. Sets the
|
setLayout | back to summary |
---|---|
public void setLayout(LayoutManager manager) Overrides java. Sets the
|
setRootPane | back to summary |
---|---|
protected void setRootPane(JRootPane root) Sets the
|
setRootPaneCheckingEnabled | back to summary |
---|---|
protected void setRootPaneCheckingEnabled(boolean enabled) Sets whether calls to
|
setTransferHandler | back to summary |
---|---|
public void setTransferHandler(TransferHandler newHandler) Sets the
If the system property Note When used with Please see How to Use Drag and Drop and Data Transfer, a section in The Java Tutorial, for more information.
|
update | back to summary |
---|---|
public void update(Graphics g) Overrides java. Just calls
|
JFrame
class. It provides an implementation of the
Java Accessibility API appropriate to frame user-interface
elements.
Access | Constructor and Description |
---|---|
protected |
Modifier and Type | Method and Description |
---|---|
public String | Returns: the localized name of the object -- can be null if this object does not have a nameOverrides java. |
public AccessibleStateSet | Returns: an instance of AccessibleStateSet containing the current state set of the objectOverrides java. |
AccessibleJFrame | back to summary |
---|---|
protected AccessibleJFrame() Constructs an |
getAccessibleName | back to summary |
---|---|
public String getAccessibleName() Overrides java. Get the accessible name of this object.
|
getAccessibleStateSet | back to summary |
---|---|
public AccessibleStateSet getAccessibleStateSet() Overrides java. Get the state of this object.
|