【发布时间】:2017-06-13 09:16:15
【问题描述】:
我为模态对话框编写了自己的类,但是当我从我的代码中调用它时,按钮点击没有任何反应。
如果我定义 setModal(false) 一切都很好。
我想并发存在一些问题,但我不确定。
我的错在哪里?
public class PauseTaskDialog extends JDialog {
private JPanel contentPane;
private JButton buttonOK;
private JButton buttonCancel;
private JCheckBox prioritisingCheckBox;
private JCheckBox simultaneousWorkCheckBox;
private JCheckBox problemsWithDataCheckBox;
private JTextArea comment;
private String taskID;
public PauseTaskDialog(String task) {
this.setContentPane(contentPane);
this.setModal(true);
this.setLocationRelativeTo(null);
this.pack();
this.setTitle("Task pause reasons");
this.taskID = task;
comment.setFont(comment.getFont().deriveFont(14f));
comment.setLineWrap(true);
comment.setWrapStyleWord(true);
buttonOK.addActionListener(e -> {
onOK();
});
buttonCancel.addActionListener(e -> {
onCancel();
});
this.setVisible(true);
}
private void onOK() {
// some code here
}
private void onCancel() {
// some code there
}
}
我以这种方式从我的代码中调用对话框:
PauseTaskDialog dialog = new PauseTaskDialog(taskID);
【问题讨论】:
-
添加你的java版本
-
@AdeelAhmed , 1.8.0_131
-
如需尽快获得更好的帮助,请发帖minimal reproducible example 或Short, Self Contained, Correct Example。
-
根据您提供的代码,
contentPane中似乎没有添加任何内容,所以除了一个空对话框之外,我不确定您的期望:P
标签: java swing actionlistener jdialog