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

📄 dialog.html

📁 jsf、swing的官方指南
💻 HTML
📖 第 1 页 / 共 4 页
字号:
                //before closing the window, you'd do                //it here.                dialog.setVisible(false);            }        }    });dialog.pack();dialog.setVisible(true);int value = ((Integer)optionPane.getValue()).intValue();if (value == JOptionPane.YES_OPTION) {    setLabel("Good.");} else if (value == JOptionPane.NO_OPTION) {    setLabel("Try using the window decorations "             + "to close the non-auto-closing dialog. "             + "You can't!");}</pre></blockquote></blockquote><h3><a name="api">The Dialog API</a></h3><blockquote>The following tables list the commonly used<code>JOptionPane</code> and <code>JDialog</code> constructors and methods.Other methods you're likely to callare defined by the<a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/Dialog.html"><code>Dialog</code></a>, <a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/Window.html"><code>Window</code></a> and<a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/Component.html"><code>Component</code></a> classesand include <CODE>pack</CODE>, <CODE>setSize</CODE>, and <CODE>setVisible</CODE>.<p>The API is listed as follows:<ul><li> <a href="#showapi">Showing Standard Modal Dialogs (using <code>JOptionPane</code> Class Methods)</a><li> <a href="#joptionpaneapi">Methods for Using <code>JOptionPane</code>sDirectly</a><li> <a href="#jdialogapi">Frequently Used <code>JDialog</code> Constructors and Methods</a></ul><p><table border=1><caption><a name="showapi">Showing Standard Modal Dialogs (Using <code>JOptionPane</code> Class Methods)</a></caption><tr><th scope="col" align=left>Method</th><th scope="col" align=left>Purpose</th></tr>  <tr>    <td scope="row"><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JOptionPane.html#showMessageDialog(java.awt.Component, java.lang.Object)">static void showMessageDialog(Component, Object)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JOptionPane.html#showMessageDialog(java.awt.Component, java.lang.Object, java.lang.String, int)">static void showMessageDialog(Component, Object, String, int)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JOptionPane.html#showMessageDialog(java.awt.Component, java.lang.Object, java.lang.String, int, javax.swing.Icon)">static void showMessageDialog(Component, Object, String, int, Icon)</a>    </td>    <td>Show a one-button, modal dialog that gives the user some information.        The arguments specify (in order) the parent component,        message, title, message type, and icon for the dialog.        See         <a href="#create">Creating and Showing Simple Dialogs</a>        for a discussion of the arguments and their effects.    </td>  </tr>  <tr>    <td scope="row"><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JOptionPane.html#showOptionDialog(java.awt.Component, java.lang.Object, java.lang.String, int, int, javax.swing.Icon, java.lang.Object[], java.lang.Object)">static int showOptionDialog(Component, Object, String, int, int, Icon, Object[], Object)</a>    </td>    <td>Show a customized modal dialog.        The arguments specify (in order) the parent component,        message, title, option type, message type, icon, options, and initial        value for the dialog.        See         <a href="#create">Creating and Showing Simple Dialogs</a>        for a discussion of the arguments and their effects.    </td>  </tr>  <tr>    <td scope="row"><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JOptionPane.html#showConfirmDialog(java.awt.Component, java.lang.Object)">static int showConfirmDialog(Component, Object)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JOptionPane.html#showConfirmDialog(java.awt.Component, java.lang.Object, java.lang.String, int)">static int showConfirmDialog(Component, Object, String, int)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JOptionPane.html#showConfirmDialog(java.awt.Component, java.lang.Object, java.lang.String, int, int)">static int showConfirmDialog(Component, Object, String, int, int)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JOptionPane.html#showConfirmDialog(java.awt.Component, java.lang.Object, java.lang.String, int, int, javax.swing.Icon)">static int showConfirmDialog(Component, Object, String, int, int, Icon)</a>    </td>    <td>Show a modal dialog that asks the user a question.        The arguments specify (in order) the parent component,        message, title, option type, message type, and icon        for the dialog.        See         <a href="#create">Creating and Showing Simple Dialogs</a>        for a discussion of the arguments and their effects.    </td>  </tr>  <tr>    <td scope="row"><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JOptionPane.html#showInputDialog(java.lang.Object)">static String showInputDialog(Object)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JOptionPane.html#showInputDialog(java.awt.Component, java.lang.Object)">static String showInputDialog(Component, Object)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JOptionPane.html#showInputDialog(java.awt.Component, java.lang.Object, java.lang.String, int)">static String showInputDialog(Component, Object, String, int)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JOptionPane.html#showInputDialog(java.awt.Component, java.lang.Object, java.lang.String, int, javax.swing.Icon, java.lang.Object[], java.lang.Object)">static String showInputDialog(Component, Object, String, int, Icon, Object[], Object)</a>    </td>    <td>Show a modal dialog that prompts the user for input.        The single-argument version specifies just the message,        with the parent component assumed to be null.        The arguments for the other versions specify (in order)        the parent component,        message, title, message type, icon, options, and initial        value for the dialog.        See         <a href="#create">Creating and Showing Simple Dialogs</a>        for a discussion of the arguments and their effects.    </td>  </tr>  <tr>    <td scope="row"><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JOptionPane.html#showInternalMessageDialog(java.awt.Component, java.lang.Object)">static void showInternalMessageDialog(...)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JOptionPane.html#showInternalOptionDialog(java.awt.Component, java.lang.Object, java.lang.String, int, int, javax.swing.Icon, java.lang.Object[], java.lang.Object)">static void showInternalOptionDialog(...)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JOptionPane.html#showInternalConfirmDialog(java.awt.Component, java.lang.Object)">static void showInternalConfirmDialog(...)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JOptionPane.html#showInternalInputDialog(java.awt.Component, java.lang.Object)">static String showInternalInputDialog(...)</a>    </td>    <td>Implement a standard dialog as an internal frame.        See the<a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JOptionPane.html"><code>JOptionPane</code> API documentation</a>        for the exact list of arguments.    </td>  </tr></table><p><table border=1><caption><a name="joptionpaneapi">Methods for Using <code>JOptionPane</code>s Directly</a></caption><tr><th scope="col" align=left>Method or Constructor</th><th scope="col" align=left>Purpose</th></tr>  <tr>    <td scope="row"><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JOptionPane.html#JOptionPane()">JOptionPane()</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JOptionPane.html#JOptionPane(java.lang.Object)">JOptionPane(Object)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JOptionPane.html#JOptionPane(java.lang.Object, int)">JOptionPane(Object, int)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JOptionPane.html#JOptionPane(java.lang.Object, int, int)">JOptionPane(Object, int, int)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JOptionPane.html#JOptionPane(java.lang.Object, int, int, javax.swing.Icon)">JOptionPane(Object, int, int, Icon)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JOptionPane.html#JOptionPane(java.lang.Object, int, int, javax.swing.Icon, java.lang.Object[])">JOptionPane(Object, int, int, Icon, Object[])</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JOptionPane.html#JOptionPane(java.lang.Object, int, int, javax.swing.Icon, java.lang.Object[], java.lang.Object)">JOptionPane(Object, int, int, Icon, Object[], Object)</a>    </td>    <td>Creates a <code>JOptionPane</code> instance.        See         <a href="#create">Creating and Showing Simple Dialogs</a>        for a discussion of the arguments and their effects.    </td>  </tr>  <tr>    <td scope="row"><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JOptionPane.html#getFrameForComponent(java.awt.Component)">static Frame getFrameForComponent(Component)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JOptionPane.html#getDesktopPaneForComponent(java.awt.Component)">static JDesktopPane getDesktopPaneForComponent(Component)</a>    </td>    <td>Handy <code>JOptionPane</code> class methods         that find the         <a href="frame.html">frame</a>        or <a href="internalframe.html">desktop pane</a>,        respectively, that the specified component is in.    </td>  </tr>  <tr>    <td scope="row"><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JOptionPane.html#getMaxCharactersPerLineCount()">int getMaxCharactersPerLineCount()</a>    </td>    <td>Determines where line breaks	will be automatically inserted 	in the option pane's text.	(The default is <code>Integer.MAX_VALUE</code>.)	To use this method, you must create a <code>JOptionPane</code>	subclass. For example, the following code results in an option pane	with one word per line:<pre>JOptionPane op = new JOptionPane("This is the message text.") {    public int getMaxCharactersPerLineCount() {        return 5;    }};</pre>    </td>  </tr></table><p><table border=1><caption><a name="jdialogapi">Frequently Used <code>JDialog</code> Constructorsand Methods</a></caption><tr><th scope="col" align=left>Method or Constructor</th><th scope="col" align=left>Purpose</th></tr></tr>  <tr>    <td scope="row"><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JDialog.html#JDialog()">JDialog()</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JDialog.html#JDialog(java.awt.Dialog)">JDialog(Dialog)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JDialog.html#JDialog(java.awt.Dialog, boolean)">JDialog(Dialog, boolean)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JDialog.html#JDialog(java.awt.Dialog, java.lang.String)">JDialog(Dialog, String)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JDialog.html#JDialog(java.awt.Dialog, java.lang.String, boolean)">JDialog(Dialog, String, boolean)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JDialog.html#JDialog(java.awt.Dialog, java.lang.String, boolean, java.awt.GraphicsConfiguration)">JDialog(Dialog, String, boolean, GraphicsConfiguration)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JDialog.html#JDialog(java.awt.Frame)">JDialog(Frame)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JDialog.html#JDialog(java.awt.Frame, boolean)">JDialog(Frame, boolean)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JDialog.html#JDialog(java.awt.Frame, java.lang.String)">JDialog(Frame, String)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JDialog.html#JDialog(java.awt.Frame, java.lang.String, boolean)">JDialog(Frame, String, boolean)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JDialog.html#JDialog(java.awt.Frame, java.lang.String, boolean, java.awt.GraphicsConfiguration)">JDialog(Frame, String, boolean, GraphicsConfiguration)</a>    </td>    <td>Creates a <code>JDialog</code> instance.        The <code>Frame</code> argument, if any,        is the frame        (usually a <code>JFrame</code> object)        that the dialog depends on.        Make the boolean argument <code>true</code>        to specify a modal dialog,        <code>false</code> or absent to specify a non-modal dialog.        You can also specify the title of the dialog,        using a string argument.    </td>  </tr>  <tr>    <td scope="row"><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JDialog.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/JDialog.html#getContentPane()">Container getContentPane()</a>    </td>    <td>Get and set the content pane,        which is usually the container        of all the dialog's components.        See <a href="toplevel.html">Using Top-Level Containers</a>        for more information.    </td>  </tr>  <tr>    <td scope="row"><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JDialog.html#setDefaultCloseOperation(int)">void setDefaultCloseOperation(int)</a>    <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JDialog.html#getDefaultCloseOperation()">int getDefaultCloseOperation()</a>    </td>    <td>Get and set what happens        when the user tries to close the dialog.        Possible values:        <code>DISPOSE_ON_CLOSE</code>,        <code>DO_NOTHING_ON_CLOSE</code>,        <code>HIDE_ON_CLOSE</code> (the default).        See <a href="frame.html#windowevents">Responding to Window-Closing Events</a>        for more information.    </td>  </tr>  <tr>    <td scope="row"><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JDialog.html#setLocationRelativeTo(java.awt.Component)">void setLocationRelativeTo(Component)</a>    </td>    <td>Centers the dialog over the specified component.    </td>  </tr>  <tr>    <td scope="row"><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JDialog.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/JDialog.html#isDefaultLookAndFeelDecorated()">static boolean isDefaultLookAndFeelDecorated()</a>    </td>    <td>Set or get a hint as to whether the dialog's window decorations        (such as borders, or widgets to close the window) should be        provided by the current look and feel.	Otherwise the dialog's        decorations will be provided by the current window manager.	See <a href="frame.html#setDefaultLookAndFeelDecorated">Specifying	Window Decorations</a> for more information.    </td>  </tr></table></blockquote><h3><a name="eg">Examples that Use Dialogs</a></h3><blockquote>This table lists examples that use <code>JOptionPane</code>or <code>JDialog</code>.To find other examples that use dialogs, see the example lists for<a href="progress.html#eg">progress bars</a>,<a href="colorchooser.html#eg">color choosers</a>, and<a href="filechooser.html#eg">file choosers</a>.<p><table><tr><th scope="col" align=left> Example</th><th scope="col" align=left> Where Described</th><th scope="col" align=left> Notes</th></tr><tr><td scope="row"> <a href="examples/index.html#DialogDemo"><code>DialogDemo</code></a>,     <br>     <a href="examples/index.html#DialogDemo"><code>CustomDialog</code></a></td><td> This section</td><td> Creates many kinds of dialogs,     using <code>JOptionPane</code> and <code>JDialog</code>.</td></tr><tr><td scope="row"> <a href="examples/index.html#Framework"><code>Framework</code></a></td><td> &#151; </td><td> Brings up a confirmation dialog when the user selects     the Quit menu item.    </td></tr><tr><td scope="row"> <a href="examples/index.html#ListDialog"><code>ListDialog</code></a></td><td> <a href="../layout/box.html">How to Use BoxLayout</a></td><td> Implements a modal dialog containing a scrolling list     and two buttons.     Doesn't use <code>JOptionPane</code>, except for the     utility method     <code>getFrameForComponent</code>.</td></tr></table>        </blockquote>        <div class=NavBit>            <a target=_top href=combobox.html>&laquo; Previous</a>            &bull;            <a target=_top href=../TOC.html>Trail</a>            &bull;            <a target=_top href=editorpane.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 Combo Boxes        <br><b>Next page:</b> How to Use Editor Panes and Text Panes    </div>    </body></html> 

⌨️ 快捷键说明

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