Making a JOptionPane with 4 options

后端 未结 2 596
悲哀的现实
悲哀的现实 2020-12-19 04:31

I need to make a custom dialog with 4 options but as far as I can tell you can only have one with three options. Here is how I would make an option pane with 3 options:

相关标签:
2条回答
  • 2020-12-19 05:14

    You can use any of the JOptionPane's option constants, you just need to supply a options array of size 4:

    public static void main(String[] args) {
        String[] options = new String[] {"Yes", "No", "Maybe", "Cancel"};
        int response = JOptionPane.showOptionDialog(null, "Message", "Title",
            JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE,
            null, options, options[0]);
    
        // Where response == 0 for Yes, 1 for No, 2 for Maybe and -1 or 3 for Escape/Cancel.
    }
    
    0 讨论(0)
  • 2020-12-19 05:24

    Simply use an options array of size 4 instead of 3...

    0 讨论(0)
提交回复
热议问题