How to make JOptionPane.showConfirmDialog have No selected by default?

前端 未结 5 726
感动是毒
感动是毒 2020-12-11 00:04

I implemented a Save As dialog in Java that prompts the user if the file already exists, and I want the No option to be selected by default. How do I do this?

Here i

5条回答
  •  执笔经年
    2020-12-11 00:46

    Use this constructor:

    JOptionPane(Object message, int messageType, int optionType,
                Icon icon, Object[] options, Object initialValue)
    

    where options specifies the buttons, and have initialValue (one of the options values) specify what the default is.

    Update: You can call showOptionDialog rather than showConfirmDialog. The former takes options and initialValue parameters.

提交回复
热议问题