JOptionPane Passing Custom Buttons

后端 未结 3 1375
陌清茗
陌清茗 2020-12-02 00:38

I\'m trying to get the value returned by custom buttons passed to JOptionPane. However the buttons I pass don\'t return a value at all. Only when the exit button is pressed

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-02 01:18

    You don't have to define your buttons explicitly.

    int result = JOptionPane.showOptionDialog(this, "Are you sure you want to...?", "Title", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { "Yes", "No" }, JOptionPane.NO_OPTION);
    if (result == JOptionPane.YES_OPTION) {
      ...
    }
    

提交回复
热议问题