Java JOptionPane Message displayInputMessage(String title, String message, String defaultInput)

Here you can find the source of displayInputMessage(String title, String message, String defaultInput)

Description

Display a dialog that gets an input string from the user.

License

Open Source License

Parameter

Parameter Description
title title of the dialog window
message prompt message that appears in the dialog
defaultInput default string which appears in the text-field

Declaration

public static String displayInputMessage(String title, String message, String defaultInput) 

Method Source Code

//package com.java2s;
/**//from ww  w  . j  a  v a  2 s .c o  m
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

import java.awt.KeyboardFocusManager;
import java.awt.Window;

import javax.swing.JOptionPane;

public class Main {
    /**
     * Display a dialog that gets an input string from the user.
     *
     * @param title title of the dialog window
     * @param message prompt message that appears in the dialog
     * @param defaultInput default string which appears in the text-field
     */
    public static String displayInputMessage(String title, String message, String defaultInput) {
        String result = JOptionPane.showInputDialog(getMainWindow(), message, "Savant",
                JOptionPane.QUESTION_MESSAGE);
        if (result != null && result.length() > 0) {
            return result;
        }
        return null;
    }

    /**
     * Choose an appropriate parent for the dialog being requested.  Usually the Savant main
     * window, but may sometimes be an open dialog.
     */
    public static Window getMainWindow() {
        return KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
    }
}

Related

  1. createPane(int type, String message, int messageMaxLength)
  2. debug(String message)
  3. display2(Component parent, String message, String title, int optionType, int messageType, Icon icon)
  4. displayEditor(Component parent, String title, String msg)
  5. displayInputMessage(String title, String message, String defaultInput)
  6. displayMessage(Component parent, String string, String title)
  7. displayMessage(Component parentComponent, String message, String windowTitle, int messageType)
  8. displayMessage(String message)
  9. displayMessagePane(String desc, String title)