javax.swing
Class JFrame

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Window
              extended by java.awt.Frame
                  extended by javax.swing.JFrame
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer, WindowConstants

public class JFrame
extends Frame
implements WindowConstants, RootPaneContainer, Accessible

A window that supports window decorations (titlebar and borders). This is an extension of Frame that provides support for the Swing architecture. Most importantly it contains a 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.

See Also:
Serialized Form

Nested Class Summary
protected  class JFrame.AccessibleJFrame
          Provides accessibility support for JFrames.
 
Nested classes/interfaces inherited from class java.awt.Frame
Frame.AccessibleAWTFrame
 
Nested classes/interfaces inherited from class java.awt.Window
Window.AccessibleAWTWindow
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  AccessibleContext accessibleContext
           
static int EXIT_ON_CLOSE
          A flag for setDefaultCloseOperation(int), indicating that the application should be exited, when this JFrame is closed.
protected  JRootPane rootPane
           
protected  boolean rootPaneCheckingEnabled
           
 
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.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
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
JFrame()
          Creates a new frame with an empty string for the title.
JFrame(GraphicsConfiguration gc)
          Creates a new JFrame in the specified GraphicsConfiguration and with an empty title.
JFrame(String title)
          Creates a new JFrame with the specified title.
JFrame(String title, GraphicsConfiguration gc)
          Creates a new JFrame in the specified GraphicsConfiguration and with the specified title.
 
Method Summary
protected  void addImpl(Component comp, Object constraints, int index)
          This method is called by all the add() methods to perform the actual adding of the component.
protected  JRootPane createRootPane()
           
protected  void frameInit()
           
 AccessibleContext getAccessibleContext()
          Returns the object that provides accessibility features for this JFrame.
 Container getContentPane()
          getContentPane
 int getDefaultCloseOperation()
          Returns a code for the default operation when the frame is closed.
 Component getGlassPane()
          getGlassPane
 JMenuBar getJMenuBar()
           
 JLayeredPane getLayeredPane()
          getLayeredPane
 Dimension getPreferredSize()
          Returns the preferred size of this container.
 JRootPane getRootPane()
          getRootPane
static boolean isDefaultLookAndFeelDecorated()
           
protected  boolean isRootPaneCheckingEnabled()
           
protected  String paramString()
          Returns a string describing the attributes for the JFrame, for use in debugging.
protected  void processKeyEvent(KeyEvent e)
          Called when a key event is dispatched and component events are enabled.
protected  void processWindowEvent(WindowEvent e)
          Dispatches this event to any listeners that are listening for WindowEvents on this window.
 void remove(Component comp)
          Removes the specified component from this container.
 void setContentPane(Container contentPane)
          setContentPane
 void setDefaultCloseOperation(int operation)
          Sets the default operation that is performed when this frame is closed.
static void setDefaultLookAndFeelDecorated(boolean decorated)
           
 void setGlassPane(Component glassPane)
          setGlassPane
 void setJMenuBar(JMenuBar menubar)
           
 void setLayeredPane(JLayeredPane layeredPane)
          setLayeredPane
 void setLayout(LayoutManager manager)
          Sets the layout manager for this container to the specified layout manager.
protected  void setRootPane(JRootPane root)
           
protected  void setRootPaneCheckingEnabled(boolean enabled)
           
 void update(Graphics g)
          Updates this container.
 
Methods inherited from class java.awt.Frame
addNotify, 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
addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getGraphicsConfiguration, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isFocusableWindow, isFocusCycleRoot, isFocused, isShowing, pack, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setAlwaysOnTop, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationRelativeTo, show, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, 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, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, 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, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, 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, 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, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, 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
A flag for 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 WindowConstants.

Since:
1.3
See Also:
Constant Field Values

accessibleContext

protected AccessibleContext accessibleContext

rootPane

protected JRootPane rootPane

rootPaneCheckingEnabled

protected boolean rootPaneCheckingEnabled
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 GraphicsConfiguration and with an empty title.

Parameters:
gc - the GraphicsConfiguration that is used for the new JFrame
See Also:
Frame#Frame(GraphicsConfiguration)

JFrame

public JFrame(String title,
              GraphicsConfiguration gc)
Creates a new JFrame in the specified 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#Frame(String, GraphicsConfiguration)
Method Detail

frameInit

protected void frameInit()

getPreferredSize

public Dimension getPreferredSize()
Description copied from class: Container
Returns the preferred size of this container.

Overrides:
getPreferredSize in class Container
Returns:
The preferred size of this container.
See Also:
Component.getMinimumSize(), Component.setPreferredSize(Dimension), LayoutManager

getJMenuBar

public JMenuBar getJMenuBar()

setJMenuBar

public void setJMenuBar(JMenuBar menubar)

setLayout

public void setLayout(LayoutManager manager)
Description copied from class: Container
Sets the layout manager for this container to the specified layout manager.

Overrides:
setLayout in class Container
Parameters:
manager - The new layout manager for this container.

setLayeredPane

public void setLayeredPane(JLayeredPane layeredPane)
Description copied from interface: RootPaneContainer
setLayeredPane

Specified by:
setLayeredPane in interface RootPaneContainer
Parameters:
layeredPane - TODO

getLayeredPane

public JLayeredPane getLayeredPane()
Description copied from interface: RootPaneContainer
getLayeredPane

Specified by:
getLayeredPane in interface RootPaneContainer

getRootPane

public JRootPane getRootPane()
Description copied from interface: RootPaneContainer
getRootPane

Specified by:
getRootPane in interface RootPaneContainer

setRootPane

protected void setRootPane(JRootPane root)

createRootPane

protected JRootPane createRootPane()

getContentPane

public Container getContentPane()
Description copied from interface: RootPaneContainer
getContentPane

Specified by:
getContentPane in interface RootPaneContainer

setContentPane

public void setContentPane(Container contentPane)
Description copied from interface: RootPaneContainer
setContentPane

Specified by:
setContentPane in interface RootPaneContainer
Parameters:
contentPane - TODO

getGlassPane

public Component getGlassPane()
Description copied from interface: RootPaneContainer
getGlassPane

Specified by:
getGlassPane in interface RootPaneContainer

setGlassPane

public void setGlassPane(Component glassPane)
Description copied from interface: RootPaneContainer
setGlassPane

Specified by:
setGlassPane in interface RootPaneContainer
Parameters:
glassPane - TODO

addImpl

protected void addImpl(Component comp,
                       Object constraints,
                       int index)
Description copied from class: Container
This method is called by all the add() methods to perform the actual adding of the component. Subclasses who wish to perform their own processing when a component is added should override this method. Any subclass doing this must call the superclass version of this method in order to ensure proper functioning of the container.

Overrides:
addImpl in class Container
Parameters:
comp - The component to be added.
constraints - The layout constraints for this component, or null if there are no constraints.
index - The index in the component list to insert this child at, or -1 to add at the end of the list.

remove

public void remove(Component comp)
Description copied from class: Container
Removes the specified component from this container.

Overrides:
remove in class Container
Parameters:
comp - The component to remove from this container.

isRootPaneCheckingEnabled

protected boolean isRootPaneCheckingEnabled()

setRootPaneCheckingEnabled

protected void setRootPaneCheckingEnabled(boolean enabled)

update

public void update(Graphics g)
Description copied from class: Container
Updates this container. The implementation of this method in this class forwards to any lightweight components in this container. If this method is subclassed, this method should still be invoked as a superclass method so that lightweight components are properly drawn.

Overrides:
update in class Container
Parameters:
g - The graphics context for this update.
See Also:
Component.paint(Graphics), Component.repaint()

processKeyEvent

protected void processKeyEvent(KeyEvent e)
Description copied from class: Component
Called when a key event is dispatched and component events are enabled. This method passes the event along to any listeners that are attached.

Overrides:
processKeyEvent in class Component
Parameters:
e - the KeyEvent to process
See Also:
KeyListener, Component.addKeyListener(KeyListener), Component.enableEvents(long)

setDefaultLookAndFeelDecorated

public static void setDefaultLookAndFeelDecorated(boolean decorated)

isDefaultLookAndFeelDecorated

public static boolean isDefaultLookAndFeelDecorated()

getAccessibleContext

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

Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in class Frame
Returns:
The accessible context (an instance of JFrame.AccessibleJFrame).

getDefaultCloseOperation

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

Returns:
One of: WindowConstants.DO_NOTHING_ON_CLOSE, WindowConstants.HIDE_ON_CLOSE, WindowConstants.DISPOSE_ON_CLOSE, EXIT_ON_CLOSE.
See Also:
setDefaultCloseOperation(int)

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.

Overrides:
paramString in class Frame
Returns:
A string describing the attributes of the JFrame.

processWindowEvent

protected void processWindowEvent(WindowEvent e)
Description copied from class: Window
Dispatches this event to any listeners that are listening for WindowEvents on this window. This method only gets invoked if it is enabled via enableEvents() or if a listener has been added.

Overrides:
processWindowEvent in class Window
Parameters:
e - The event to process.

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: WindowConstants.DO_NOTHING_ON_CLOSE, WindowConstants.HIDE_ON_CLOSE, WindowConstants.DISPOSE_ON_CLOSE and WindowConstants.EXIT_ON_CLOSE).
Throws:
IllegalArgumentException - if operation is not one of the specified codes.
See Also:
getDefaultCloseOperation()