Eclipse插件(RCP)消息对话框组件 MessageDialog

Eclipse提供了较完整、标准的消息对话组件,下面介绍一下MessageDialog的使用。

简介

MessageDialog位于org.eclipse.jface.dialogs包中,继承自IconAndMessageDialogMessageDialog官方API

字段

类型字段名描述
static final intNONE0没有图标的对话框
static final intERROR1带有错误(error)图标,或简单按钮的消息提示框
static final intINFORMATION2带有信息(info)图标,或简单按钮的消息提示框
static final intQUESTION3带有问号(question)图标,或 Yes/No 按钮的消息提示框
static final intWARNING4带有告警(WARNING)图标,或简单按钮的消息提示框
static final intCONFIRM5带有确认( CONFIRM)图标,或带有 OK/Cancel 按钮的消息提示框
static final intQUESTION_WITH_CANCEL6带有信息( QUESTION_WITH_CANCEL)图标,或Yes/No/Cancel 按钮的消息提示框

构造方法

MessageDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage, int dialogImageType, String[] dialogButtonLabels, int defaultIndex)

内置方法

  • protected void buttonPressed(int buttonId)
    Notifies that this dialog’s button with the given id has been pressed.
  • protected void configureShell(Shell shell)
    Configures the given shell in preparation for opening this window in it.
  • protected Button createButton(Composite parent, int id, String label, boolean defaultButton)
    Creates a new button with the given id.
  • protected void createButtonsForButtonBar(Composite parent)
    Adds buttons to this dialog’s button bar.
  • protected Control createCustomArea(Composite parent)
    Creates and returns the contents of an area of the dialog which appears below the message and above the button bar.
  • protected Control createDialogArea(Composite parent)
    This implementation of the Dialog framework method creates and lays out a composite and calls createMessageArea and createCustomArea to populate it.
  • protected boolean customShouldTakeFocus()
    Return whether or not we should apply the workaround where we take focus for the default button or if that should be determined by the dialog.
  • protected Button getButton(int index)
    Gets a button in this dialog’s button bar.
  • protected String[] getButtonLabels()
    An accessor for the labels to use on the buttons.
  • protected int getDefaultButtonIndex()
    An accessor for the index of the default button in the button array.
  • Image getImage()
    Returns the image to display beside the message in this dialog.
  • protected int getMinimumMessageWidth()
    Returns the minimum message area width in pixels This determines the minimum width of the dialog.
  • protected void handleShellCloseEvent()
    Handle the shell close.
  • int open()
    Opens this message dialog, creating it first if it has not yet been created.
  • ⭐️static boolean open(int kind, Shell parent, String title, String message, int style)
    Convenience method to open a simple dialog as specified by the kind flag.
  • ⭐️static boolean openConfirm(Shell parent, String title, String message)
    Convenience method to open a simple confirm (OK/Cancel) dialog.
  • ⭐️static void openError(Shell parent, String title, String message)
    Convenience method to open a standard error dialog.
  • ⭐️static void openInformation(Shell parent, String title, String message)
    Convenience method to open a standard information dialog.
  • ⭐️static boolean openQuestion(Shell parent, String title, String message)
    Convenience method to open a simple Yes/No question dialog.
  • ⭐️static void openWarning(Shell parent, String title, String message)
    Convenience method to open a standard warning dialog.
  • ⭐️protected void setButtonLabels(String[] buttonLabels)
    A mutator for the button labels.
  • ⭐️protected void setButtons(Button[] buttons)
    A mutator for the array of buttons in the button bar.

其中带⭐️的方法开箱即用,使用也比较频繁,示例见下一章。具有较强业务的消息对话框用户可以根据构造方法构造,最后调用.open() 打开。

简单使用

	Shell shell = Display.getCurrent().getActiveShell();
	MessageDialog.openInformation(shell, "提示", "静态检查未通过,请查看静态检查结果并处理问题");
	MessageDialog.openError(shell, "错误消息", "一条错误的消息");
	MessageDialog.openQuestion(shell, "询问", "询问一下,这是询问消息么?");
	MessageDialog.openWarning(shell, "警告", "请别再随意造轮子,我够用了!!!");
	MessageDialog.openConfirm(shell, "确认", "你没有造其他轮子吧?");
  • 信息对话框
    在这里插入图片描述
  • 错误对话框
    在这里插入图片描述
  • 询问对话框
    在这里插入图片描述
  • 警告对话框
    在这里插入图片描述
  • 确认对话框
    在这里插入图片描述
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值