views:

409

answers:

3

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:

        Frame refFrame = DialogUtils.getReferenceFrame();

        ///TODO:
        /// - Use DialogUtils
        int option = JOptionPane.showOptionDialog(refFrame,
            msg,
            rsc.str("918"),
            JOptionPane.YES_NO_CANCEL_OPTION,
            JOptionPane.INFORMATION_MESSAGE,
            DialogUtils.INFO_ICON,
            options,
            options[0]);

But I could not find some sort of open ended substitution for YES_NO_CANCEL_OPTION. Is there a way to make the JOptionPane allow four choices?

+1  A: 

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

Michael Borgwardt
+2  A: 

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"};
    JOptionPane.showOptionDialog(null, "Title", "Message", 
        JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, 
        null, options, options[0]);
}
Peter Nix
A: 

How about reading the JOptionPane API, where you will find a link to the Swing tutorial with a working example?

camickr