加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – SWT – 修改窗口关闭按钮(红色X)

发布时间:2020-12-15 04:10:54 所属栏目:Java 来源:网络整理
导读:当用户使用窗口关闭按钮(红色X)按钮关闭任何应用程序窗口时.它会导致我的应用程序出现Widget is Disposed问题.当他们使用我提供的关闭应用程序关闭窗口时.一切正常. @Overrideprotected void createButtonsForButtonBar(Composite parent) { createButton(pa
当用户使用窗口关闭按钮(红色X)按钮关闭任何应用程序窗口时.它会导致我的应用程序出现Widget is Disposed问题.当他们使用我提供的关闭应用程序关闭窗口时.一切正常.

@Override
protected void createButtonsForButtonBar(Composite parent) {
   createButton(parent,IDialogConstants.OK_ID,"Close Aplot",true);
}

@Override
protected void okPressed() {
   getShell().setVisible(false);
}

>你能抓住窗口关闭按钮(红色X)按下以使用上面的代码吗?
>你能禁用窗口关闭按钮(红色X)吗?

解决方法

在Shell上收听SWT.Close.

This应该有所帮助:

public static void main(String[] args)
{
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.addListener(SWT.Close,new Listener()
    {
        public void handleEvent(Event event)
        {
            int style = SWT.APPLICATION_MODAL | SWT.YES | SWT.NO;
            MessageBox messageBox = new MessageBox(shell,style);
            messageBox.setText("Information");
            messageBox.setMessage("Close the shell?");
            event.doit = messageBox.open() == SWT.YES;
        }
    });

    shell.pack();
    shell.open();
    while (!shell.isDisposed())
    {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

它将提示用户验证决定.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读