Here you can find the source of displayInputMessage(String title, String message, String defaultInput)
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 |
public static String displayInputMessage(String title, String message, String defaultInput)
//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(); } }