Is there a multiple input JOptionPane in Java?
-
11-07-2019 - |
Question
I was wondering if there is a JOptionPane where you can get multiple inputs from a user instead of just one? If not, how could i accomplish this using some type of prompt. I am creating Battleship, and wanted to prompt the user to specify locations to place each ship.
Thanks,
Tomek
Solution
The object that you pass in as the message to the JOptionPane can be graphical components, so something like this should work:
JPanel panel = new JPanel();
// Populate your panel components here.
int ret = JOptionPane.showConfirmDialog(parent, panel, "Title", JOptionPane.YES_NO_OPTION);
if ( ret == JOptionPane.YES_OPTION )
{
// Read component values.
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow