Getting the Results
Now that we’ve seen how to create all sorts of useful dialog boxes, it’s time to take a look at how to retrieve information about the user’s interaction with the dialog. Table 10-7 showed the return types of the various methods. Here’s a quick summary of what the returned values mean.
- Input Dialogs
The versions that do not take an array of selection values return a
String. This is the data entered by the user. The methods that do take an array of selection values return anObjectreflecting the selected option. It’s up to the L&F to determine the component used for presenting the options. Typically, aJComboBoxis used if there are fewer than 20 choices, and aJListis used if there are 20 or more.[14] In any case, if the user presses the Cancel button,nullis returned.- Confirm Dialogs
These methods return an
intreflecting the button pressed by the user. The possible values are:YES_OPTION,NO_OPTION,CANCEL_OPTION, andOK_OPTION.CLOSED_OPTIONis returned if the user closes the window without selecting anything.- Message Dialogs
These methods have
voidreturn types because they do not request a user response.- Option Dialogs
If no options are specified, this method returns one of the constant values
YES_OPTION,NO_OPTION,CANCEL_OPTION, andOK_OPTION. If options are explicitly defined, the return value gives the index to the array of options that matches the button selected by the user.CLOSED_OPTIONis returned if the user closes the window without selecting anything. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access