This week's giveaway is in the Cloud/Virtualization forum. We're giving away four copies of Production-Ready Serverless (Operational Best Practices) and have Yan Cui on-line! See this thread for details.
I wasn't sure where to post this or if there was a helps forum, but having asked many questions here, I thought I would contribute a solution or helper that I found valuable and would like to share!
I was surprised in searching myself for an answer on this subject how difficult it was to find a clear solution or coded around it, making it far more complicated than it needs to be. Even the Oracle docs were hard to follow. In Intellij, you only see a couple overloaded methods instead of the full range of options unless keep typing commas, and so naive people like me think there are not any remaining overloaded methods. By the time you get to the Icon and button parameters you thin you are at the end... Not so here! These default parameters fall after the icon and appear as the last two parameters.
The first of the two defaults I have marked bold, 'null', is a very cool parameter allowing you to enter an array of options (String) of 'selection values'.
A list with with a default picked
JOptionPane.showInputDialog(null, "What primary color is your favorite?", "Pick a color", JOptionPane.PLAIN_MESSAGE, null,ans, ans)
No list (null) and default string
JOptionPane.showInputDialog(null, "What primary color is your favorite?", "Pick a color", JOptionPane.PLAIN_MESSAGE, null,null, "Red")
Being a Java newbee, I missed it. I struggled with this for a few days before finding what I did and thought I would post so the next newbee wouldn't struggle as long. LOL! There are actually 2. The second does the same as the first except you also have the option of restricting the user to options in an array while providing a default. There is also more control, offering a Title and Icon if preferred.