549 * @param title the <code>String</code> to display in the
550 * dialog title bar
551 * @param messageType the type of message to be displayed:
552 * <code>ERROR_MESSAGE</code>,
553 * <code>INFORMATION_MESSAGE</code>,
554 * <code>WARNING_MESSAGE</code>,
555 * <code>QUESTION_MESSAGE</code>,
556 * or <code>PLAIN_MESSAGE</code>
557 * @param icon the <code>Icon</code> image to display
558 * @param selectionValues an array of <code>Object</code>s that
559 * gives the possible selections
560 * @param initialSelectionValue the value used to initialize the input
561 * field
562 * @return user's input, or <code>null</code> meaning the user
563 * canceled the input
564 * @exception HeadlessException if
565 * <code>GraphicsEnvironment.isHeadless</code> returns
566 * <code>true</code>
567 * @see java.awt.GraphicsEnvironment#isHeadless
568 */
569 public static Object showInputDialog(Component parentComponent,
570 Object message, String title, int messageType, Icon icon,
571 Object[] selectionValues, Object initialSelectionValue)
572 throws HeadlessException {
573 JOptionPane pane = new JOptionPane(message, messageType,
574 OK_CANCEL_OPTION, icon,
575 null, null);
576
577 pane.setWantsInput(true);
578 pane.setSelectionValues(selectionValues);
579 pane.setInitialSelectionValue(initialSelectionValue);
580 pane.setComponentOrientation(((parentComponent == null) ?
581 getRootFrame() : parentComponent).getComponentOrientation());
582
583 int style = styleFromMessageType(messageType);
584 JDialog dialog = pane.createDialog(parentComponent, title, style);
585
586 pane.selectInitialValue();
587 dialog.show();
588 dialog.dispose();
838 * or <code>PLAIN_MESSAGE</code>
839 * @param icon the icon to display in the dialog
840 * @param options an array of objects indicating the possible choices
841 * the user can make; if the objects are components, they
842 * are rendered properly; non-<code>String</code>
843 * objects are
844 * rendered using their <code>toString</code> methods;
845 * if this parameter is <code>null</code>,
846 * the options are determined by the Look and Feel
847 * @param initialValue the object that represents the default selection
848 * for the dialog; only meaningful if <code>options</code>
849 * is used; can be <code>null</code>
850 * @return an integer indicating the option chosen by the user,
851 * or <code>CLOSED_OPTION</code> if the user closed
852 * the dialog
853 * @exception HeadlessException if
854 * <code>GraphicsEnvironment.isHeadless</code> returns
855 * <code>true</code>
856 * @see java.awt.GraphicsEnvironment#isHeadless
857 */
858 public static int showOptionDialog(Component parentComponent,
859 Object message, String title, int optionType, int messageType,
860 Icon icon, Object[] options, Object initialValue)
861 throws HeadlessException {
862 JOptionPane pane = new JOptionPane(message, messageType,
863 optionType, icon,
864 options, initialValue);
865
866 pane.setInitialValue(initialValue);
867 pane.setComponentOrientation(((parentComponent == null) ?
868 getRootFrame() : parentComponent).getComponentOrientation());
869
870 int style = styleFromMessageType(messageType);
871 JDialog dialog = pane.createDialog(parentComponent, title, style);
872
873 pane.selectInitialValue();
874 dialog.show();
875 dialog.dispose();
876
877 Object selectedValue = pane.getValue();
|
549 * @param title the <code>String</code> to display in the
550 * dialog title bar
551 * @param messageType the type of message to be displayed:
552 * <code>ERROR_MESSAGE</code>,
553 * <code>INFORMATION_MESSAGE</code>,
554 * <code>WARNING_MESSAGE</code>,
555 * <code>QUESTION_MESSAGE</code>,
556 * or <code>PLAIN_MESSAGE</code>
557 * @param icon the <code>Icon</code> image to display
558 * @param selectionValues an array of <code>Object</code>s that
559 * gives the possible selections
560 * @param initialSelectionValue the value used to initialize the input
561 * field
562 * @return user's input, or <code>null</code> meaning the user
563 * canceled the input
564 * @exception HeadlessException if
565 * <code>GraphicsEnvironment.isHeadless</code> returns
566 * <code>true</code>
567 * @see java.awt.GraphicsEnvironment#isHeadless
568 */
569 @SuppressWarnings("deprecation")
570 public static Object showInputDialog(Component parentComponent,
571 Object message, String title, int messageType, Icon icon,
572 Object[] selectionValues, Object initialSelectionValue)
573 throws HeadlessException {
574 JOptionPane pane = new JOptionPane(message, messageType,
575 OK_CANCEL_OPTION, icon,
576 null, null);
577
578 pane.setWantsInput(true);
579 pane.setSelectionValues(selectionValues);
580 pane.setInitialSelectionValue(initialSelectionValue);
581 pane.setComponentOrientation(((parentComponent == null) ?
582 getRootFrame() : parentComponent).getComponentOrientation());
583
584 int style = styleFromMessageType(messageType);
585 JDialog dialog = pane.createDialog(parentComponent, title, style);
586
587 pane.selectInitialValue();
588 dialog.show();
589 dialog.dispose();
839 * or <code>PLAIN_MESSAGE</code>
840 * @param icon the icon to display in the dialog
841 * @param options an array of objects indicating the possible choices
842 * the user can make; if the objects are components, they
843 * are rendered properly; non-<code>String</code>
844 * objects are
845 * rendered using their <code>toString</code> methods;
846 * if this parameter is <code>null</code>,
847 * the options are determined by the Look and Feel
848 * @param initialValue the object that represents the default selection
849 * for the dialog; only meaningful if <code>options</code>
850 * is used; can be <code>null</code>
851 * @return an integer indicating the option chosen by the user,
852 * or <code>CLOSED_OPTION</code> if the user closed
853 * the dialog
854 * @exception HeadlessException if
855 * <code>GraphicsEnvironment.isHeadless</code> returns
856 * <code>true</code>
857 * @see java.awt.GraphicsEnvironment#isHeadless
858 */
859 @SuppressWarnings("deprecation")
860 public static int showOptionDialog(Component parentComponent,
861 Object message, String title, int optionType, int messageType,
862 Icon icon, Object[] options, Object initialValue)
863 throws HeadlessException {
864 JOptionPane pane = new JOptionPane(message, messageType,
865 optionType, icon,
866 options, initialValue);
867
868 pane.setInitialValue(initialValue);
869 pane.setComponentOrientation(((parentComponent == null) ?
870 getRootFrame() : parentComponent).getComponentOrientation());
871
872 int style = styleFromMessageType(messageType);
873 JDialog dialog = pane.createDialog(parentComponent, title, style);
874
875 pane.selectInitialValue();
876 dialog.show();
877 dialog.dispose();
878
879 Object selectedValue = pane.getValue();
|