private void cancelButtonPressed() {
jPane = new JOptionPane("quit?", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null, buttons, buttons[1]);
jPane.setName("WPane");
dialog = jPane.createDialog(jPane.getParent(), "Confirm Dialog");
dialog.setVisible(true);
dialog.dispose();
Object selectedValue = jPane.getValue();
System.out.println("selectedValue:" + selectedValue);
if(selectedValue == null)
System.out.println("selectedValue:" + selectedValue);
//return CLOSED_OPTION;
if(buttons == null) {
if(selectedValue instanceof Integer) {
//return ((Integer)selectedValue).intValue();
System.out.println("selectedValue instanceof Integer, selectedValue:" + selectedValue);
//return CLOSED_OPTION;
}
}
for(int counter = 0, maxCounter = buttons.length;
counter < maxCounter; counter++) {
if(buttons[counter].equals(selectedValue)){
System.out.println("buttons[counter].equals(selectedValue) selectedValue:" + selectedValue);
//return counter;
}
}
//return CLOSED_OPTION;
}
コンストラクターで、ボタンの名前を設定します。
buttons[0]= new JButton("Yes");
buttons[1]= new JButton("No");
buttons[0].setName("Yes_Next_Btn");
buttons[1].setName("No_Back_Btn");
問題は、setNames
コンポーネントJOptionPane
とボタンを変更する必要があるということでした。使用しないように:JOptionPane.showConfirmDialog
。
そしてこの場合:ボタンをクリックすると(はい、いいえ)、「X」をクリックした場合にのみ値が表示されません。終了すると、が表示されますnull
。