public class JFrame extends Frame implements WindowConstants, RootPaneContainer, Accessible
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.Frame
s, JFrames support the
Swing Pluggable Look & Feel architecture.Modifier and Type | Class and Description |
---|---|
protected class |
JFrame.AccessibleJFrame
Provides accessibility support for
JFrame s. |
Frame.AccessibleAWTFrame
Window.AccessibleAWTWindow
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
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 |
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
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
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. |
Modifier and Type | Method and Description |
---|---|
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.
|
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setIconImage, setMaximizedBounds, setMenuBar, setResizable, setState, setTitle, setUndecorated
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
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
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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getFont, postEvent
public static final int EXIT_ON_CLOSE
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
.protected AccessibleContext accessibleContext
protected boolean rootPaneCheckingEnabled
public JFrame()
public JFrame(String title)
JFrame
with the specified title.title
- the frame title (null
permitted).public JFrame(GraphicsConfiguration gc)
GraphicsConfiguration
and with an empty title.gc
- the GraphicsConfiguration
that is used for
the new JFrame
Frame.Frame(GraphicsConfiguration)
public JFrame(String title, GraphicsConfiguration gc)
GraphicsConfiguration
and with the specified title.title
- the title for the new JFrame
gc
- the GraphicsConfiguration
that is used for
the new JFrame
Frame.Frame(String, GraphicsConfiguration)
protected void frameInit()
public Dimension getPreferredSize()
Container
getPreferredSize
in class Container
Component.getMinimumSize()
,
Component.setPreferredSize(Dimension)
,
LayoutManager
public JMenuBar getJMenuBar()
public void setJMenuBar(JMenuBar menubar)
public void setLayout(LayoutManager manager)
Container
public void setLayeredPane(JLayeredPane layeredPane)
RootPaneContainer
setLayeredPane
in interface RootPaneContainer
layeredPane
- TODOpublic JLayeredPane getLayeredPane()
RootPaneContainer
getLayeredPane
in interface RootPaneContainer
public JRootPane getRootPane()
RootPaneContainer
getRootPane
in interface RootPaneContainer
protected void setRootPane(JRootPane root)
protected JRootPane createRootPane()
public Container getContentPane()
RootPaneContainer
getContentPane
in interface RootPaneContainer
public void setContentPane(Container contentPane)
RootPaneContainer
setContentPane
in interface RootPaneContainer
contentPane
- TODOpublic Component getGlassPane()
RootPaneContainer
getGlassPane
in interface RootPaneContainer
public void setGlassPane(Component glassPane)
RootPaneContainer
setGlassPane
in interface RootPaneContainer
glassPane
- TODOprotected void addImpl(Component comp, Object constraints, int index)
Container
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.public void remove(Component comp)
Container
protected boolean isRootPaneCheckingEnabled()
protected void setRootPaneCheckingEnabled(boolean enabled)
public void update(Graphics g)
Container
update
in class Container
g
- The graphics context for this update.Component.paint(Graphics)
,
Component.repaint()
protected void processKeyEvent(KeyEvent e)
Component
processKeyEvent
in class Component
e
- the KeyEvent
to processKeyListener
,
Component.addKeyListener(KeyListener)
,
Component.enableEvents(long)
public static void setDefaultLookAndFeelDecorated(boolean decorated)
public static boolean isDefaultLookAndFeelDecorated()
public AccessibleContext getAccessibleContext()
JFrame
.getAccessibleContext
in interface Accessible
getAccessibleContext
in class Frame
JFrame.AccessibleJFrame
).public int getDefaultCloseOperation()
WindowConstants.HIDE_ON_CLOSE
.protected String paramString()
JFrame
,
for use in debugging. The return value is guaranteed to be
non-null
, but the format may vary between implementations.paramString
in class Frame
JFrame
.protected void processWindowEvent(WindowEvent e)
Window
WindowEvents
on this window. This method only gets
invoked if it is enabled via enableEvents()
or if
a listener has been added.processWindowEvent
in class Window
e
- The event to process.public void setDefaultCloseOperation(int operation)
HIDE_ON_CLOSE
. When
EXIT_ON_CLOSE
is specified this method calls
SecurityManager.checkExit(0)
which might throw a
SecurityException
.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
).IllegalArgumentException
- if operation
is not one of
the specified codes.getDefaultCloseOperation()