⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frame.html

📁 jsf、swing的官方指南
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<blockquote>The following tables list the commonly used<code>JFrame</code> constructors and methods.Other methods you might want to callare defined by the<a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/Frame.html"><code>java.awt.Frame</code></a>,<a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/Window.html"><code>java.awt.Window</code></a>, and<a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/Component.html"><code>java.awt.Component</code></a> classes,from which <code>JFrame</code> descends.<p>Because each <code>JFrame</code> object has a root pane,frames have support for interposing input and painting behaviorin front of the frame's children, placing children on different "layers",and for Swing menu bars.These topics are introduced in<a href="toplevel.html">Using Top-Level Containers</a>and explained in detail in <a href="rootpane.html">How to Use Root Panes</a>.<p>The API for using frames falls into these categories:<ul><li><a href="#creating">Creating and Setting Up a Frame</a><li><a href="#sizeplace">Setting the Window Size and Location</a><li><a href="#rootpane">Methods Related to the Root Pane</a></ul><p><table border=1> <caption><a name="creating">Creating and Setting Up a Frame</a></caption><tr><th align=left>Method or Constructor</th><th align=left>Purpose </th></tr>  <tr>    <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFrame.html#JFrame()">JFrame()</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFrame.html#JFrame(java.lang.String)">JFrame(String)</a></td><td>Create a frame that is initially invisible.    The <code>String</code> argument provides a title for the frame.    To make the frame visible,    invoke <code>setVisible(true)</code> on it.</td></tr>  <tr>    <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFrame.html#setDefaultCloseOperation(int)">void setDefaultCloseOperation(int)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFrame.html#getDefaultCloseOperation()">int getDefaultCloseOperation()</a></td><td>Set or get the operation that occurs when the user pushes    the close button on this frame. Possible choices are:    <ul>    <li><code>DO_NOTHING_ON_CLOSE</code>    <li><code>HIDE_ON_CLOSE</code>    <li><code>DISPOSE_ON_CLOSE</code>    <li><code>EXIT_ON_CLOSE</code>    </ul>    The first three constants are defined in the <a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/WindowConstants.html"><code>WindowConstants</code></a>    interface, which <code>JFrame</code> implements.      The <code>EXIT_ON_CLOSE</code> constant is defined in    the<a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFrame.html"><code>JFrame</code></a>    class.</td></tr>  <tr>    <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/Frame.html#setIconImage(java.awt.Image)">void setIconImage(Image)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/Frame.html#getIconImage()">Image getIconImage()</a><br><em>(in <code>Frame</code>)</em></td><td>Set or get the icon that represents the frame.Note that the argument is a <a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/Image.html">java.awt.Image</a> object, not a <code>javax.swing.ImageIcon</code> (or any other <code>javax.swing.Icon</code> implementation).</td></tr>  <tr>    <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/Frame.html#setTitle(java.lang.String)">void setTitle(String)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/Frame.html#getTitle()">String getTitle()</a><br><em>(in <code>Frame</code>)</em></td><td>Set or get the frame's title.</td></tr>  <tr>    <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/Frame.html#setUndecorated(boolean)">void setUndecorated(boolean)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/Frame.html#isUndecorated()">boolean isUndecorated()</a><br><em>(in <code>Frame</code>)</em></td><td>Set or get whether the window system should provide decorations     for this frame.    Works only if the frame is not yet displayable    (hasn't been packed or shown).    Typically used with <a class="TutorialLink" target="_top" href="../../extra/fullscreen/index.html">full-screen exclusive mode</a>    or to enable custom window decorations.</td></tr>  <tr>    <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFrame.html#setDefaultLookAndFeelDecorated(boolean)">static void setDefaultLookAndFeelDecorated(boolean)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFrame.html#isDefaultLookAndFeelDecorated()">static boolean isDefaultLookAndFeelDecorated()</a>    </td>    <td>Determine whether subsequently created <code>JFrame</code>s        should have their Window decorations (such as borders, widgets for        closing the window, title) provided by the current        look and feel.  Note that this is only a hint, as some look and        feels may not support this feature.</table><p><table border=1> <caption><a name="sizeplace">Setting the Window Size and Location</a></caption><tr><th align=left>Method</th><th align=left>Purpose </th></tr>  <tr>    <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/Window.html#pack()">void pack()</a><br><em>(in <code>Window</code>)</em></td><td>Size the windowso that all its contents are at or above their preferred sizes.</td></tr>  <tr>    <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/Component.html#setSize(int,%20int)">void setSize(int, int)</a><br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/Component.html#setSize(java.awt.Dimension)">void setSize(Dimension)</a><br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/Component.html#getSize()">Dimension getSize()</a><br><em>(in <code>Component</code>)</em></td><td>Set or get the total size of the window.The integer arguments to <code>setSize</code> specify the width and height,respectively.</td></tr>  <tr>    <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/Component.html#setBounds(int,%20int,%20int,%20int)">void setBounds(int, int, int, int)</a><br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/Component.html#setBounds(java.awt.Rectangle)">void setBounds(Rectangle)</a><br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/Component.html#getBounds()">Rectangle getBounds()</a><br><em>(in <code>Component</code>)</em></td><td>Set or get the size and position of the window.For the integer version of <code>setBounds</code>,the window's upper left corner is at the <em>x, y</em> locationspecified by the first two arguments,and has the width and height specified by the last two arguments.</td></tr>  <tr>    <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/Component.html#setLocation(int,%20int)">void setLocation(int, int)</a><br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/Component.html#getLocation()">Point getLocation()</a><br><em>(in <code>Component</code>)</em></td><td>Set or get the location of the upper left corner of the window.The parameters are the <em>x</em> and <em>y</em> values, respectively.</td></tr>  <tr>    <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/Window.html#setLocationRelativeTo(java.awt.Component)">void setLocationRelativeTo(Component)</a><br><em>(in <code>Window</code>)</em></td><td>Position the windowso that it's centered over the specified component.If the argument is <code>null</code>,the window is centered onscreen.To properly center the window,you should invoke this method after the window's size has been set.</td></tr></table><p><table border=1><caption><a name="rootpane">Methods Related to the Root Pane</a></caption><tr><th align=left>Method</th><th align=left>Purpose</th></tr>  <tr>    <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFrame.html#setContentPane(java.awt.Container)">void setContentPane(Container)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFrame.html#getContentPane()">Container getContentPane()</a></td><td>Set or get the frame's content pane.    The content pane contains the frame's visible GUI components    and should be opaque.</td></tr>  <tr>    <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFrame.html#createRootPane()">JRootPane createRootPane()</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFrame.html#setRootPane(javax.swing.JRootPane)">void setRootPane(JRootPane)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFrame.html#getRootPane()">JRootPane getRootPane()</a></td><td>Create, set, or get the frame's root pane. The root pane    manages the interior of the frame including the content pane,    the glass pane, and so on.</td></tr>  <tr>    <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFrame.html#setJMenuBar(javax.swing.JMenuBar)">void setJMenuBar(JMenuBar)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFrame.html#getJMenuBar()">JMenuBar getJMenuBar()</a></td><td>Set or get the frame's menu bar    to manage a set of menus for the frame.</td></tr>  <tr>    <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFrame.html#setGlassPane(java.awt.Component)">void setGlassPane(Component)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFrame.html#getGlassPane()">Component getGlassPane()</a></td><td>Set or get the frame's glass pane.    You can use the glass pane to intercept mouse events    or paint on top of your program's GUI.</td></tr>  <tr>    <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFrame.html#setLayeredPane(javax.swing.JLayeredPane)">void setLayeredPane(JLayeredPane)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFrame.html#getLayeredPane()">JLayeredPane getLayeredPane()</a></td><td>Set or get the frame's layered pane.    You can use the frame's layered pane to put components on top of    or behind other components.</td></tr></table></blockquote><h3><a name="eg">Examples that Use Frames</a></h3><blockquote>All of the standalone applications in this trailuse <code>JFrame</code>.The following table lists a fewand tells you where each is discussed.<p><table><tr><th align=left> Example</th><th align=left> Where Described</th><th align=left> Notes</th></tr><tr><td> <a href="examples/index.html#FrameDemo"><code>FrameDemo</code></a></td><td> <a href="#anexample">The Example Explained</a></td><td> Displays a basic frame with one component.</td></tr><tr><td> <a href="examples/index.html#FrameDemo2"><code>FrameDemo2</code></a></td><td> <a href="#setDefaultLookAndFeelDecorated">Specifying Window Decorations</a></td><td> Lets you create frames with various window decorations.</td></tr><tr><td> <a href="examples/index.html#Framework"><code>Framework</code></a></td><td> &#151;</td><td> A study in creating and destroying windows,     in implementing a menu bar,     and in exiting an application.</td></tr><tr><td> <a href="examples/index.html#LayeredPaneDemo"><code>LayeredPaneDemo</code></a></td><td> <a href="layeredpane.html">How to Use Layered Panes</a></td><td> Illustrates how to use a layered pane     (but not the frame's layered pane).</td></tr> <tr><td> <a href="examples/index.html#GlassPaneDemo"><code>GlassPaneDemo</code></a></td><td> <a href="rootpane.html#glasspane">The Glass Pane</a></td><td> Illustrates the use of a frame's glass pane.</td></tr> <tr><td> <a href="examples/index.html#MenuDemo"><code>MenuDemo</code></a></td><td> <a href="menu.html">How to Use Menus</a></td><td> Shows how to put a <code>JMenuBar</code> in a <code>JFrame</code>.</td></tr></table>        </blockquote>        <div class=NavBit>            <a target=_top href=formattedtextfield.html>&laquo; Previous</a>            &bull;            <a target=_top href=../TOC.html>Trail</a>            &bull;            <a target=_top href=internalframe.html>Next &raquo;</a>        </div>    </div>    <div id=Footer><div id=TagNotes>    Problems with the examples? Try <a target="_blank"        href=../../information/run-examples.html>Compiling and Running        the Examples: FAQs</a>.    <br>    Complaints? Compliments? Suggestions? <a target="_blank"        href="http://developer.sun.com/contact/tutorial_feedback.jsp">Give    us your feedback</a>.<br><br>    <a target="_blank" href="../../information/copyright.html">Copyright</a>    1995-2006 Sun Microsystems, Inc.  All rights reserved.    <span id=Download></span></div>     </div>    <div class=PrintHeaders>        <b>Previous page:</b> How to Use Formatted Text Fields        <br><b>Next page:</b> How to Use Internal Frames    </div>    </body></html> 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -