javax.swing

Class JFrame

public class JFrame extends Frame implements WindowConstants, RootPaneContainer, Accessible

A window that supports window decorations (titlebar and borders). This is an extension of {@link java.awt.Frame} that provides support for the Swing architecture. Most importantly it contains a {@link JRootPane} as it's only top-level child, that manages the content pane, the menu and a glass pane. Also, unlike java.awt.Frames, JFrames support the Swing Pluggable Look & Feel architecture.
Nested Class Summary
protected classJFrame.AccessibleJFrame
Provides accessibility support for JFrames.
Field Summary
protected AccessibleContextaccessibleContext
static intEXIT_ON_CLOSE
A flag for {@link #setDefaultCloseOperation(int)}, indicating that the application should be exited, when this JFrame is closed.
protected JRootPanerootPane
protected booleanrootPaneCheckingEnabled
Constructor Summary
JFrame()
Creates a new frame with an empty string for the title.
JFrame(String title)
Creates a new JFrame with the specified title.
JFrame(GraphicsConfiguration gc)
Creates a new JFrame in the specified {@link GraphicsConfiguration} and with an empty title.
JFrame(String title, GraphicsConfiguration gc)
Creates a new JFrame in the specified {@link GraphicsConfiguration} and with the specified title.
Method Summary
protected voidaddImpl(Component comp, Object constraints, int index)
protected JRootPanecreateRootPane()
protected voidframeInit()
AccessibleContextgetAccessibleContext()
Returns the object that provides accessibility features for this JFrame.
ContainergetContentPane()
intgetDefaultCloseOperation()
Returns a code for the default operation when the frame is closed.
ComponentgetGlassPane()
JMenuBargetJMenuBar()
JLayeredPanegetLayeredPane()
DimensiongetPreferredSize()
JRootPanegetRootPane()
static booleanisDefaultLookAndFeelDecorated()
protected booleanisRootPaneCheckingEnabled()
protected StringparamString()
Returns a string describing the attributes for the JFrame, for use in debugging.
protected voidprocessKeyEvent(KeyEvent e)
protected voidprocessWindowEvent(WindowEvent e)
voidremove(Component comp)
voidsetContentPane(Container contentPane)
voidsetDefaultCloseOperation(int operation)
Sets the default operation that is performed when this frame is closed.
static voidsetDefaultLookAndFeelDecorated(boolean decorated)
voidsetGlassPane(Component glassPane)
voidsetJMenuBar(JMenuBar menubar)
voidsetLayeredPane(JLayeredPane layeredPane)
voidsetLayout(LayoutManager manager)
protected voidsetRootPane(JRootPane root)
protected voidsetRootPaneCheckingEnabled(boolean enabled)
voidupdate(Graphics g)

Field Detail

accessibleContext

protected AccessibleContext accessibleContext

EXIT_ON_CLOSE

public static final int EXIT_ON_CLOSE
A flag for {@link #setDefaultCloseOperation(int)}, indicating that the application should be exited, when this JFrame is closed. Note that in version 1.4, the equivalent constant has been added to {@link WindowConstants}.

Since: 1.3

rootPane

protected JRootPane rootPane

rootPaneCheckingEnabled

protected boolean rootPaneCheckingEnabled

UNKNOWN: rootPaneCheckingEnabled is false to comply with J2SE 5.0

Constructor Detail

JFrame

public JFrame()
Creates a new frame with an empty string for the title.

JFrame

public JFrame(String title)
Creates a new JFrame with the specified title.

Parameters: title the frame title (null permitted).

JFrame

public JFrame(GraphicsConfiguration gc)
Creates a new JFrame in the specified {@link GraphicsConfiguration} and with an empty title.

Parameters: gc the GraphicsConfiguration that is used for the new JFrame

See Also: Frame

JFrame

public JFrame(String title, GraphicsConfiguration gc)
Creates a new JFrame in the specified {@link GraphicsConfiguration} and with the specified title.

Parameters: title the title for the new JFrame gc the GraphicsConfiguration that is used for the new JFrame

See Also: Frame

Method Detail

addImpl

protected void addImpl(Component comp, Object constraints, int index)

createRootPane

protected JRootPane createRootPane()

frameInit

protected void frameInit()

getAccessibleContext

public AccessibleContext getAccessibleContext()
Returns the object that provides accessibility features for this JFrame.

Returns: The accessible context (an instance of {@link AccessibleJFrame}).

getContentPane

public Container getContentPane()

getDefaultCloseOperation

public int getDefaultCloseOperation()
Returns a code for the default operation when the frame is closed. The default value is {@link WindowConstants#HIDE_ON_CLOSE}.

Returns: One of: {@link WindowConstants#DO_NOTHING_ON_CLOSE}, {@link WindowConstants#HIDE_ON_CLOSE}, {@link WindowConstants#DISPOSE_ON_CLOSE}, {@link #EXIT_ON_CLOSE}.

See Also: JFrame

getGlassPane

public Component getGlassPane()

getJMenuBar

public JMenuBar getJMenuBar()

getLayeredPane

public JLayeredPane getLayeredPane()

getPreferredSize

public Dimension getPreferredSize()

getRootPane

public JRootPane getRootPane()

isDefaultLookAndFeelDecorated

public static boolean isDefaultLookAndFeelDecorated()

isRootPaneCheckingEnabled

protected boolean isRootPaneCheckingEnabled()

paramString

protected String paramString()
Returns a string describing the attributes for the JFrame, for use in debugging. The return value is guaranteed to be non-null, but the format may vary between implementations.

Returns: A string describing the attributes of the JFrame.

processKeyEvent

protected void processKeyEvent(KeyEvent e)

processWindowEvent

protected void processWindowEvent(WindowEvent e)

remove

public void remove(Component comp)

setContentPane

public void setContentPane(Container contentPane)

setDefaultCloseOperation

public void setDefaultCloseOperation(int operation)
Sets the default operation that is performed when this frame is closed. The default is HIDE_ON_CLOSE. When EXIT_ON_CLOSE is specified this method calls SecurityManager.checkExit(0) which might throw a SecurityException.

Parameters: operation a code for the operation (one of: {@link WindowConstants#DO_NOTHING_ON_CLOSE}, {@link WindowConstants#HIDE_ON_CLOSE}, {@link WindowConstants#DISPOSE_ON_CLOSE} and {@link WindowConstants#EXIT_ON_CLOSE}).

Throws: IllegalArgumentException if operation is not one of the specified codes.

See Also: getDefaultCloseOperation

setDefaultLookAndFeelDecorated

public static void setDefaultLookAndFeelDecorated(boolean decorated)

setGlassPane

public void setGlassPane(Component glassPane)

setJMenuBar

public void setJMenuBar(JMenuBar menubar)

setLayeredPane

public void setLayeredPane(JLayeredPane layeredPane)

setLayout

public void setLayout(LayoutManager manager)

setRootPane

protected void setRootPane(JRootPane root)

setRootPaneCheckingEnabled

protected void setRootPaneCheckingEnabled(boolean enabled)

update

public void update(Graphics g)