Java examples for Swing:JDialog
Show input dialog with specified title and message.
/*//from w w w .j a v a 2 s. c o m * Copyright (c) 2011, 2020, Frank Jiang and/or its affiliates. All rights * reserved. SwingUtils.java is built in 2012-11-2. */ //package com.java2s; import java.awt.Component; import javax.swing.JOptionPane; public class Main { /** * Show input dialog with specified title and message. * * @param parent * the parent component of the input dialog, set {@code null} if * not has one * @param title * the title of the dialog * @param message * the message to display * @return the input string, may be an empty string */ public static String inputDialog(Component parent, String title, String message) { return JOptionPane.showInputDialog(parent, message, title, JOptionPane.INFORMATION_MESSAGE); } /** * Show input dialog with specified title, message and initial input * content. * * @param parent * the parent component of the input dialog, set {@code null} if * not has one * @param title * the title of the dialog * @param message * the message to display * @param initial * the initial input content * @return the input string, may be an empty string */ public static String inputDialog(Component parent, String title, String message, String initial) { Object obj = JOptionPane.showInputDialog(parent, message, title, JOptionPane.INFORMATION_MESSAGE, null, null, initial); if (obj == null) return null; else return obj.toString(); } }