how-to

Dialogs

Input dialog

For working with dialogs in Java you need use this include:

import javax.swing.JOptionPane;

Input dialog can is easy dialog for reading (and returning) one String value. The simplest form is,

String sValue = JOptionPane.showInputDialog( "Get value:" );

where first parameter is displayed message. The dialog returns null value, when user click on Cancel button.


In other form you can specify initial value for readed variable:

String sValue = JOptionPane.showInputDialog( "Get value:", 3 );

It is possible to set dialog title too:

String sValue = JOptionPane.showInputDialog( null, "Get value:", "Title", JOptionPane.QUESTION_MESSAGE );