[英]How to add buttons to the JFace ErrorDialog
我正在尝试向此弹出对话框添加“取消”按钮,该对话框基本上只是为用户提供一些信息,并允许他们单击“是”或查看详细信息。 问题是没有取消按钮,我想添加一个。
该对话框是一个JFace ErrorDialog
,它使用预制的MultiStatus
显示错误消息。 对话框打开,并显示“确定”按钮或“取消”按钮。 无论如何,是否可以直接操纵对话框如何创建按钮或我可以用来更改其外观的其他方法? 任何帮助表示赞赏!
if (ErrorDialog.openError(shell,
Messages.ConsistencyAction_confirm_dialog_title, null,
multiStatus, IStatus.WARNING) != Window.OK) {
return;
}
这是我要更改的对话框。 基本上,这是在进行检查以确保有人按ok,否则,您将退出。 您可以通过点击角落的红色X退出它,但是拥有一个按钮会减少混乱。
您可以扩展ErrorDialog
类,以便可以覆盖createButtonsForButtonBar
方法。
例如,这来自Eclipse p2安装插件:
public class OkCancelErrorDialog extends ErrorDialog {
public OkCancelErrorDialog(Shell parentShell, String dialogTitle, String message, IStatus status, int displayMask) {
super(parentShell, dialogTitle, message, status, displayMask);
}
@Override
protected void createButtonsForButtonBar(Composite parent) {
// create OK, Cancel and Details buttons
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, true);
createDetailsButton(parent);
}
}
使用此方法,您不能使用静态的ErrorDialog.openError
方法,而必须执行以下操作:
OkCancelErrorDialog dialog = new OkCancelErrorDialog(shell, Messages.ConsistencyAction_confirm_dialog_title, null, multiStatus, IStatus.WARNING);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.