我有一個自定義對話框,收集用戶的兩個字符串。創建對話框時,我使用OK_CANCEL_OPTION作爲選項類型。 Evertyhings的作品除了當用戶點擊取消或關閉對話框時,它具有相同的效果,點擊確定按鈕。JOptionPane.createDialog和OK_CANCEL_OPTION
我該如何處理取消和關閉事件?
繼承人的代碼,我說的是:
JTextField topicTitle = new JTextField();
JTextField topicDesc = new JTextField();
Object[] message = {"Title: ", topicTitle, "Description: ", topicDesc};
JOptionPane pane = new JOptionPane(message, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
JDialog getTopicDialog = pane.createDialog(null, "New Topic");
getTopicDialog.setVisible(true);
// Do something here when OK is pressed but just dispose when cancel is pressed.
感謝編輯+1 – mKorbel 2011-12-15 15:03:06
非常非常感謝你們。使用showOptionDialog代替createDialog的作品。 – philb28 2011-12-15 15:10:54