javax.swing

接口
异常
java.lang.Object
  继承者 java.awt.Component
      继承者 java.awt.Container
          继承者 java.awt.Window
              继承者 java.awt.Frame
                  继承者 javax.swing.JFrame
所有已实现的接口:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer, WindowConstants

public class JFrame
     
extends Frame
implements WindowConstants, Accessible, RootPaneContainer

java.awt.Frame 的扩展版本,该版本添加了对 JFC/Swing 组件架构的支持。有关使用 JFrame 的面向任务的文档,请参阅 The Java Tutorial 中的 How to Make Frames 一节。

JFrame 类与 Frame 轻微不兼容。与其他所有 JFC/Swing 顶层容器一样,JFrame 包含一个 JRootPane 作为其唯一的子容器。根据规定,根窗格所提供的内容窗格应该包含 JFrame 所显示的所有非菜单组件。这不同于 AWT Frame。为了方便地使用 add 及其变体,已经重写了 removesetLayout,以在必要时将其转发到 contentPane。这意味着可以编写:

       frame.add(child);
 
子级将被添加到 contentPane。内容窗格始终是非 null 的。试图将其设置为 null 会导致 JFrame 抛出异常。默认的内容窗格上会设置有 BorderLayout 管理器。有关添加、移除和设置 JFrameLayoutManager 的详细信息,请参阅 RootPaneContainer

Frame 不同,当用户试图关闭窗口时,JFrame 知道如何进行响应。用户关闭窗口时,默认的行为只是简单地隐藏 JFrame。要更改默认的行为,可调用方法 setDefaultCloseOperation(int)。要使 JFrame 的行为与 Frame 实例相同,请使用 setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE)

有关内容窗格和根窗格提供的其他功能的更多信息,请参阅 The Java Tutorial 中的 Using Top-Level Containers 一节。

在多屏幕环境中,可以在不同的屏幕设备上创建一个 JFrame。有关更多信息,请参阅 Frame

警告:Swing 不是线程安全的。有关更多信息,请参阅 Swing's Threading Policy

警告:此类的序列化对象与以后的 Swing 版本不兼容。当前序列化支持适用于短期存储,或适用于在运行相同 Swing 版本的应用程序之间进行 RMI(Remote Method Invocation,远程方法调用)。从 1.4 版本开始,已在 java.beans 包中添加了支持所有 JavaBeansTM 长期存储的功能。请参阅 XMLEncoder

另请参见:
JRootPane, setDefaultCloseOperation(int), WindowListener.windowClosing(java.awt.event.WindowEvent), RootPaneContainer

嵌套类摘要
protected  class JFrame.AccessibleJFrame
          此类实现对 JFrame 类的可访问性支持。
 
从类 java.awt.Frame 继承的嵌套类/接口
Frame.AccessibleAWTFrame
 
从类 java.awt.Window 继承的嵌套类/接口
Window.AccessibleAWTWindow
 
从类 java.awt.Container 继承的嵌套类/接口
Container.AccessibleAWTContainer
 
从类 java.awt.Component 继承的嵌套类/接口
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
字段摘要
protected  AccessibleContext accessibleContext
          可访问的上下文属性。
static int EXIT_ON_CLOSE
          退出应用程序后的默认窗口关闭操作。
protected  JRootPane rootPane
          JRootPane 实例管理此窗体的 contentPane 和可选的 menuBar,以及 glassPane
protected  boolean rootPaneCheckingEnabled
          如果为 true,则将对 addsetLayout 的调用转发到 contentPane
 
从类 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
 
从类 java.awt.Component 继承的字段
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
从接口 javax.swing.WindowConstants 继承的字段
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE
 
从接口 java.awt.image.ImageObserver 继承的字段
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
构造方法摘要
JFrame()
          构造一个初始时不可见的新窗体。
JFrame(GraphicsConfiguration gc)
          以屏幕设备的指定 GraphicsConfiguration 和空白标题创建一个 Frame
JFrame(String title)
          创建一个新的、初始不可见的、具有指定标题的 Frame
JFrame(String title, GraphicsConfiguration gc)
          创建一个具有指定标题和指定屏幕设备的 GraphicsConfigurationJFrame
 
方法摘要
protected  void addImpl(Component comp, Object constraints, int index)
          添加指定的子 Component
protected  JRootPane createRootPane()
          由构造方法调用,以创建默认的 rootPane
protected  void frameInit()
          由构造方法调用,以适当地初始化 JFrame
 AccessibleContext getAccessibleContext()
          获得与此 JFrame 关联的 AccessibleContext。
 Container getContentPane()
          返回此窗体的 contentPane 对象
 int getDefaultCloseOperation()
          返回用户在此窗体上发起 "close" 时执行的操作。
 Component getGlassPane()
          返回此窗体的 glassPane 对象。
 Graphics getGraphics()
          为组件创建一个图形上下文。
 JMenuBar getJMenuBar()
          返回此窗体上设置的菜单栏。
 JLayeredPane getLayeredPane()
          返回此窗体的 layeredPane 对象。
 JRootPane getRootPane()
          返回此窗体的 rootPane 对象。
 TransferHandler getTransferHandler()
          获取 transferHandler 属性。
static boolean isDefaultLookAndFeelDecorated()
          如果新创建的 JFrame 应该由当前外观为其提供 Window 装饰,则返回 true。
protected  boolean isRootPaneCheckingEnabled()
          返回是否将对 addsetLayout 的调用转发到 contentPane
protected  String paramString()
          返回此 JFrame 的字符串表示形式。
protected  void processWindowEvent(WindowEvent e)
          处理此组件上发生的窗口事件。
 void remove(Component comp)
          从该容器中移除指定组件。
 void repaint(long time, int x, int y, int width, int height)
          在 time 毫秒内重绘此组件的指定矩形区域。
 void setContentPane(Container contentPane)
          设置 contentPane 属性。
 void setDefaultCloseOperation(int operation)
          设置用户在此窗体上发起 "close" 时默认执行的操作。
static void setDefaultLookAndFeelDecorated(boolean defaultLookAndFeelDecorated)
          提供一个关于新创建的 JFrame 是否应该具有当前外观为其提供的 Window 装饰(如边框、关闭窗口的小部件、标题等等)的提示。
 void setGlassPane(Component glassPane)
          设置 glassPane 属性。
 void setIconImage(Image image)
          设置要作为此窗口图标显示的图像。
 void setJMenuBar(JMenuBar menubar)
          设置此窗体的菜单栏。
 void setLayeredPane(JLayeredPane layeredPane)
          设置 layeredPane 属性。
 void setLayout(LayoutManager manager)
          设置 LayoutManager
protected  void setRootPane(JRootPane root)
          设置 rootPane 属性。
protected  void setRootPaneCheckingEnabled(boolean enabled)
          设置是否将对 addsetLayout 的调用转发到 contentPane
 void setTransferHandler(TransferHandler newHandler)
          设置 transferHandler 属性,该属性是支持向此组件传输数据的机制。
 void update(Graphics g)
          只是调用 paint(g)
 
从类 java.awt.Frame 继承的方法
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setResizable, setState, setTitle, setUndecorated
 
从类 java.awt.Window 继承的方法
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOwnedWindows, getOwner, getOwnerlessWindows, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setVisible, show, toBack, toFront
 
从类 java.awt.Container 继承的方法
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, 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, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
从类 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, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, 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, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resize, resize, setBackground, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusUpCycle
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
从接口 java.awt.MenuContainer 继承的方法
getFont, postEvent
 

字段详细信息

EXIT_ON_CLOSE

public static final int EXIT_ON_CLOSE
退