Search code examples
javaswingjoptionpane

What role does optionType play in a JOptionPane OptionsDialog?


Note: Please pay attention to the fact that this is an Options Dialog here, not a Confirm Dialog. That makes a difference in what I'm asking and how Swing behaves!

I looked at a good code example of an Option Dialog in action, but was confused by one thing:

If you are supplying the dialog with all the options in the options parameter, of what use/role/significance is the optionType parameter?

According to the Javadocs you're options are:

  • DEFAULT_OPTION
  • YES_NO_OPTION
  • YES_NO_CANCEL_OPTION; or
  • OK_CANCEL_OPTION

How do these different options affect the resultant dialog, or does Swing just ignore them?!? Thanks in advance!


Solution

  • The optionType parameter defines amongst which options the user will have to choose. If you use YES_NO_CANCEL_OPTION, it will display 3 buttons, one for each option:

    • YES
    • NO
    • CANCEL

    enter image description here

    The same goes for all possible optionType values.