Swing JFrame API 常用方法
1. 构造和设置JFrame
|
JFrame() |
Create a frame that is initially invisible. The String argument provides a title for the frame. To make the frame visible, invoke setVisible(true) on it. |
|
void setDefaultCloseOperation(int) |
Set or get the operation that occurs when the user pushes the close button on this frame. Possible choices are:
WindowConstants interface, which JFrame implements. The EXIT_ON_CLOSE constant is defined in the JFrame class. |
| void setIconImage(Image) Image getIconImage() |
Set or get the icon that represents the frame. Note that the argument is a java.awt.Image object, not ajavax.swing.ImageIcon (or any other javax.swing.Icon implementation). |
| void setTitle(String) String getTitle() |
Set or get the frame title. |
| void setUndecorated(boolean) boolean isUndecorated() |
Set or get whether this frame should be decorated. Works only if the frame is not yet displayable (has not been packed or shown). Typically used with full-screen exclusive mode or to enable custom window decorations. |
| static void setDefaultLookAndFeelDecorated(boolean) static boolean isDefaultLookAndFeelDecorated() |
Determine whether subsequently created JFrames should have their Window decorations (such as borders, and widgets for closing the window) provided by the current look-and-feel. Note that this is only a hint, as some look and feels may not support this feature. |
2. 设置窗体的位置和大小
| void pack() | Size the window so that all its contents are at or above their preferred sizes. |
| void setSize(int, int) void setSize(Dimension) Dimension getSize() |
Set or get the total size of the window. The integer arguments to setSize specify the width and height, respectively. |
| void setBounds(int, int, int, int) void setBounds(Rectangle) Rectangle getBounds() |
Set or get the size and position of the window. For the integer version of setBounds, the window upper left corner is at the x, y location specified by the first two arguments, and has the width and height specified by the last two arguments. |
| void setLocation(int, int) Point getLocation() |
Set or get the location of the upper left corner of the window. The parameters are the x and y values, respectively. |
| void setLocationRelativeTo(Commponent) | Position the window so that it is centered over the specified component. If the argument is null, the window is centered onscreen. To properly center the window, you should invoke this method after the window size has been set. |
3. 和Root Pane相关的方法
| void setContentPane(Container) Container getContentPane() |
Set or get the frame content pane. The content pane contains the visible GUI components within the frame. |
| JRootPane createRootPane() void setRootPane(JRootPane) JRootPane getRootPane() |
Create, set, or get the frame root pane. The root pane manages the interior of the frame including the content pane, the glass pane, and so on. |
| void setJMenuBar(JMenuBar) JMenuBar getJMenuBar() |
Set or get the frame menu bar to manage a set of menus for the frame. |
| void setGlassPane(Component) Component getGlassPane() |
Set or get the frame glass pane. You can use the glass pane to intercept mouse events or paint on top of your program GUI. |
| void setLayeredPane(JLayeredPane) JLayeredPane getLayeredPane() |
Set or get the frame layered pane. You can use the frame layered pane to put components on top of or behind other components. |
浙公网安备 33010602011771号