簡體   English   中英

如何將按鈕添加到JFace ErrorDialog

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM