你好我想在按下 jdialog 的确定按钮时触发一些 Action ,我知道你可以这样做
int rep =JOptionPane.showConfirmDialog(null, pangesfac, "Gestion des chambres a facturer", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
if(rep == JOptionPane.OK_OPTION) {//actions to do}
但在我的例子中,当按下 ok 按钮时,我想要一个外部 Controller 来处理必须完成的事情(我的代码由 mvc 构建)。那么如何在确定按钮上设置 Action 监听器?
最佳答案
这是可能的,但不像向 OK 按钮添加 ActionListener 那样简单。您必须使用 PropertyChangeListener。
本页显示了一个示例:http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html#stayup
但是您可能需要重新考虑您的设计。您仍然可以将结果从 JOptionPane 传递到您的 Controller ,而无需捕获事件本身。
关于java - 如何在 jdialog 的 ok 选项上设置 actionlistener?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15533920/