Module java.desktop
Package javax.swing
Class JFrame
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- java.awt.Window
-
- java.awt.Frame
-
- javax.swing.JFrame
-
All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Accessible
,RootPaneContainer
,WindowConstants
Pack()函数:使此窗口的大小适合其子组件的首选大小和布局。如果其中一个尺寸小于前面调用setMinimumSize方法所指定的最小尺寸,则会自动放大窗口的结果宽度和高度。
public void setDefaultCloseOperation(int operation) 设置默认情况下,当用户在此Frame上启动“关闭”时将发生的操作。您必须指定以下选项之一:
DO_NOTHING_ON_CLOSE
(defined inWindowConstants
): Don't do anything; require the program to handle the operation in thewindowClosing
method of a registeredWindowListener
object.- 不做任何事,需要程序去处理(一个已经注册了的WindowListener对象的windowClosing方法)的操作
HIDE_ON_CLOSE
(defined inWindowConstants
): Automatically hide the frame after invoking any registeredWindowListener
objects.- 在调用了任何已经注册了的WindowListener对象后自动隐藏Frame。
DISPOSE_ON_CLOSE
(defined inWindowConstants
): Automatically hide and dispose the frame after invoking any registeredWindowListener
objects.- 调用任何已注册的WindowListener对象后自动隐藏和处理Frame。
EXIT_ON_CLOSE
(defined inWindowConstants
): Exit the application using theSystem
exit
method. Use this only in applications.- 使用System exit方法退出应用程序。仅在应用程序中使用。
该值默认设置为HIDE_ON_CLOSE。此属性值的更改将引发属性更改事件,属性名称为“defaultCloseOperation”。
public Component add(Component comp, int index) 在容器的给定位置添加此组件。
public void remove(Component comp)
从容器中移除指定的组件。如果comp不是rootPane,这将把调用转发到contentPane。如果comp不是JFrame或contentPane的子元素,这将不起任何作用。
public Container getContentPane()
返回此frame的contentPane对象。
@BeanProperty(bound=false) public Graphics getGraphics()
为该组件创建图形上下文。如果该组件当前不可显示,则此方法将返回null。
@BeanProperty(bound=false, hidden=true, description="The client area of the frame where child components are normally inserted.") public void setContentPane(Container contentPane)
设置contentPane属性。此方法由构造函数调用。Swing的绘画体系结构需要包含层次结构中的不透明JComponent。这通常由content窗格提供。如果替换内容窗格,建议使用不透明的JComponent替换它。
@BeanProperty(bound=false, hidden=true, description="The menubar for accessing pulldown menus from this frame.") public void setJMenuBar(JMenuBar menubar)
设置这个frame的菜单栏。