src/share/classes/javax/swing/JOptionPane.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 114  * </tr>
 115  * <tr>
 116  *  <td style="background-color:#FFe0d0">input value</td>
 117  * </tr>
 118  * <tr>
 119  *   <td style="background-color:#FFe0d0" colspan=2>option buttons</td>
 120  * </tr>
 121  * </table>
 122  *
 123  * The basic appearance of one of these dialog boxes is generally
 124  * similar to the picture at the right, although the various
 125  * look-and-feels are
 126  * ultimately responsible for the final result.  In particular, the
 127  * look-and-feels will adjust the layout to accommodate the option pane's
 128  * <code>ComponentOrientation</code> property.
 129  * <br style="clear:all">
 130  * <p>
 131  * <b>Parameters:</b><br>
 132  * The parameters to these methods follow consistent patterns:
 133  * <blockquote>
 134  * <dl compact>
 135  * <dt>parentComponent<dd>
 136  * Defines the <code>Component</code> that is to be the parent of this
 137  * dialog box.
 138  * It is used in two ways: the <code>Frame</code> that contains
 139  * it is used as the <code>Frame</code>
 140  * parent for the dialog box, and its screen coordinates are used in
 141  * the placement of the dialog box. In general, the dialog box is placed
 142  * just below the component. This parameter may be <code>null</code>,
 143  * in which case a default <code>Frame</code> is used as the parent,
 144  * and the dialog will be
 145  * centered on the screen (depending on the {@literal L&F}).
 146  * <dt><a name=message>message</a><dd>
 147  * A descriptive message to be placed in the dialog box.
 148  * In the most common usage, message is just a <code>String</code> or
 149  * <code>String</code> constant.
 150  * However, the type of this parameter is actually <code>Object</code>. Its
 151  * interpretation depends on its type:
 152  * <dl compact>
 153  * <dt>Object[]<dd>An array of objects is interpreted as a series of
 154  *                 messages (one per object) arranged in a vertical stack.
 155  *                 The interpretation is recursive -- each object in the
 156  *                 array is interpreted according to its type.
 157  * <dt>Component<dd>The <code>Component</code> is displayed in the dialog.
 158  * <dt>Icon<dd>The <code>Icon</code> is wrapped in a <code>JLabel</code>
 159  *               and displayed in the dialog.
 160  * <dt>others<dd>The object is converted to a <code>String</code> by calling
 161  *               its <code>toString</code> method. The result is wrapped in a
 162  *               <code>JLabel</code> and displayed.
 163  * </dl>
 164  * <dt>messageType<dd>Defines the style of the message. The Look and Feel
 165  * manager may lay out the dialog differently depending on this value, and
 166  * will often provide a default icon. The possible values are:
 167  * <ul>
 168  * <li><code>ERROR_MESSAGE</code>
 169  * <li><code>INFORMATION_MESSAGE</code>
 170  * <li><code>WARNING_MESSAGE</code>
 171  * <li><code>QUESTION_MESSAGE</code>
 172  * <li><code>PLAIN_MESSAGE</code>
 173  * </ul>
 174  * <dt>optionType<dd>Defines the set of option buttons that appear at
 175  * the bottom of the dialog box:
 176  * <ul>
 177  * <li><code>DEFAULT_OPTION</code>
 178  * <li><code>YES_NO_OPTION</code>
 179  * <li><code>YES_NO_CANCEL_OPTION</code>
 180  * <li><code>OK_CANCEL_OPTION</code>
 181  * </ul>
 182  * You aren't limited to this set of option buttons.  You can provide any
 183  * buttons you want using the options parameter.
 184  * <dt>options<dd>A more detailed description of the set of option buttons
 185  * that will appear at the bottom of the dialog box.
 186  * The usual value for the options parameter is an array of
 187  * <code>String</code>s. But
 188  * the parameter type is an array of <code>Objects</code>.
 189  * A button is created for each object depending on its type:
 190  * <dl compact>
 191  * <dt>Component<dd>The component is added to the button row directly.
 192  * <dt>Icon<dd>A <code>JButton</code> is created with this as its label.
 193  * <dt>other<dd>The <code>Object</code> is converted to a string using its
 194  *              <code>toString</code> method and the result is used to
 195  *              label a <code>JButton</code>.
 196  * </dl>
 197  * <dt>icon<dd>A decorative icon to be placed in the dialog box. A default
 198  * value for this is determined by the <code>messageType</code> parameter.
 199  * <dt>title<dd>The title for the dialog box.
 200  * <dt>initialValue<dd>The default selection (input value).
 201  * </dl>
 202  * </blockquote>
 203  * <p>
 204  * When the selection is changed, <code>setValue</code> is invoked,
 205  * which generates a <code>PropertyChangeEvent</code>.
 206  * <p>
 207  * If a <code>JOptionPane</code> has configured to all input
 208  * <code>setWantsInput</code>
 209  * the bound property <code>JOptionPane.INPUT_VALUE_PROPERTY</code>
 210  *  can also be listened


   1 /*
   2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 114  * </tr>
 115  * <tr>
 116  *  <td style="background-color:#FFe0d0">input value</td>
 117  * </tr>
 118  * <tr>
 119  *   <td style="background-color:#FFe0d0" colspan=2>option buttons</td>
 120  * </tr>
 121  * </table>
 122  *
 123  * The basic appearance of one of these dialog boxes is generally
 124  * similar to the picture at the right, although the various
 125  * look-and-feels are
 126  * ultimately responsible for the final result.  In particular, the
 127  * look-and-feels will adjust the layout to accommodate the option pane's
 128  * <code>ComponentOrientation</code> property.
 129  * <br style="clear:all">
 130  * <p>
 131  * <b>Parameters:</b><br>
 132  * The parameters to these methods follow consistent patterns:
 133  * <blockquote>
 134  * <dl>
 135  * <dt>parentComponent<dd>
 136  * Defines the <code>Component</code> that is to be the parent of this
 137  * dialog box.
 138  * It is used in two ways: the <code>Frame</code> that contains
 139  * it is used as the <code>Frame</code>
 140  * parent for the dialog box, and its screen coordinates are used in
 141  * the placement of the dialog box. In general, the dialog box is placed
 142  * just below the component. This parameter may be <code>null</code>,
 143  * in which case a default <code>Frame</code> is used as the parent,
 144  * and the dialog will be
 145  * centered on the screen (depending on the {@literal L&F}).
 146  * <dt><a name=message>message</a><dd>
 147  * A descriptive message to be placed in the dialog box.
 148  * In the most common usage, message is just a <code>String</code> or
 149  * <code>String</code> constant.
 150  * However, the type of this parameter is actually <code>Object</code>. Its
 151  * interpretation depends on its type:
 152  * <dl>
 153  * <dt>Object[]<dd>An array of objects is interpreted as a series of
 154  *                 messages (one per object) arranged in a vertical stack.
 155  *                 The interpretation is recursive -- each object in the
 156  *                 array is interpreted according to its type.
 157  * <dt>Component<dd>The <code>Component</code> is displayed in the dialog.
 158  * <dt>Icon<dd>The <code>Icon</code> is wrapped in a <code>JLabel</code>
 159  *               and displayed in the dialog.
 160  * <dt>others<dd>The object is converted to a <code>String</code> by calling
 161  *               its <code>toString</code> method. The result is wrapped in a
 162  *               <code>JLabel</code> and displayed.
 163  * </dl>
 164  * <dt>messageType<dd>Defines the style of the message. The Look and Feel
 165  * manager may lay out the dialog differently depending on this value, and
 166  * will often provide a default icon. The possible values are:
 167  * <ul>
 168  * <li><code>ERROR_MESSAGE</code>
 169  * <li><code>INFORMATION_MESSAGE</code>
 170  * <li><code>WARNING_MESSAGE</code>
 171  * <li><code>QUESTION_MESSAGE</code>
 172  * <li><code>PLAIN_MESSAGE</code>
 173  * </ul>
 174  * <dt>optionType<dd>Defines the set of option buttons that appear at
 175  * the bottom of the dialog box:
 176  * <ul>
 177  * <li><code>DEFAULT_OPTION</code>
 178  * <li><code>YES_NO_OPTION</code>
 179  * <li><code>YES_NO_CANCEL_OPTION</code>
 180  * <li><code>OK_CANCEL_OPTION</code>
 181  * </ul>
 182  * You aren't limited to this set of option buttons.  You can provide any
 183  * buttons you want using the options parameter.
 184  * <dt>options<dd>A more detailed description of the set of option buttons
 185  * that will appear at the bottom of the dialog box.
 186  * The usual value for the options parameter is an array of
 187  * <code>String</code>s. But
 188  * the parameter type is an array of <code>Objects</code>.
 189  * A button is created for each object depending on its type:
 190  * <dl>
 191  * <dt>Component<dd>The component is added to the button row directly.
 192  * <dt>Icon<dd>A <code>JButton</code> is created with this as its label.
 193  * <dt>other<dd>The <code>Object</code> is converted to a string using its
 194  *              <code>toString</code> method and the result is used to
 195  *              label a <code>JButton</code>.
 196  * </dl>
 197  * <dt>icon<dd>A decorative icon to be placed in the dialog box. A default
 198  * value for this is determined by the <code>messageType</code> parameter.
 199  * <dt>title<dd>The title for the dialog box.
 200  * <dt>initialValue<dd>The default selection (input value).
 201  * </dl>
 202  * </blockquote>
 203  * <p>
 204  * When the selection is changed, <code>setValue</code> is invoked,
 205  * which generates a <code>PropertyChangeEvent</code>.
 206  * <p>
 207  * If a <code>JOptionPane</code> has configured to all input
 208  * <code>setWantsInput</code>
 209  * the bound property <code>JOptionPane.INPUT_VALUE_PROPERTY</code>
 210  *  can also be listened