how-to

Dialogs

How to create input dialog with predefined options

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

import javax.swing.JOptionPane;

You can create input dialog with firmly predefined options:

/* -- options */

Object[] o = { "One", "Two", "Tree" };

/* -- show dialog */

Object selected = JOptionPane.showInputDialog( null , "Question", "Title", JOptionPane.QUESTION_MESSAGE, null, o, "Two" );

/* -- if selected -> then show result */>

if ( selected != null ) System.out.println( selected.toString() );

This dialog is shown: