【问题标题】:Widget is disposedWidget 被配置
【发布时间】:2010-07-26 16:03:28
【问题描述】:

大家好

我有一个主屏幕,有以下键绑定:

shell.getDisplay().addFilter(SWT.KeyUp, new Listener() {
    @Override
    public void handleEvent(Event event) {
        switch (event.keyCode) {
        case SWT.ESC:
            shell.close();
            break;
        case SWT.F12:
            display.syncExec(new Runnable() {
                @Override
                public void run() {
                new Venda(shell);
                }
            });                 
            break;                  
        default:
            break;
        }               
    }
});

当按下 F12 时,搜索的屏幕被打开。销售画面的构造器:

public Venda(Shell parent) {
        super(parent);
        this.shell = new Shell(getParent(),SWT.APPLICATION_MODAL);
        this.display = getParent().getDisplay();
        this.shell.setMaximized(true);
        this.shell.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_DARK_GREEN));
        this.fontText = new Font(shell.getDisplay(), new FontData("Arial", 28, SWT.NORMAL));
        this.fontLabel = new Font(shell.getDisplay(), new FontData("Arial", 13, SWT.NORMAL));
        this.shell.setText("Cupom Fiscal - Venda Produto");
        this.criaCampos();
        this.configuraTeclaAtalho();
        this.shell.open();
        while (!display.isDisposed()) {
            if (!display.isDisposed() && !display.readAndDispatch()) {
                display.sleep();
            }
        }
    }

在销售画面按F3,搜索画面打开。我的问题是:第一次打开销售屏幕时,搜索屏幕正常工作,但如果关闭销售屏幕并再次打开,搜索屏幕不起作用,投射错误:小部件已处置。 错误发生在第 02 行,源代码如下。 变量“abreFechaCaixa”验证是否应该打开销售屏幕。

    if(!abreFechaCaixa){
        MessageBox msg = new MessageBox(shell, SWT.ICON_WARNING | SWT.YES | SWT.NO);
        msg.setMessage("Caixa Fechado, deseja abrir?");
    msg.setText(shell.getText());
    if(msg.open() == SWT.YES){
        abreCaixa();
    }
    }
if(abreFechaCaixa){
    display.syncExec(new Runnable() {
        @Override
    public void run() {
                new Consulta(shell,"Cupom Fiscal - Consulta Produto");
    }
    });
}

构造函数的搜索屏幕:

public Consulta(Shell parent) {
                super(parent);
        this.shell = new Shell(parent, SWT.APPLICATION_MODAL);
        this.display = getParent().getDisplay();
        this.shell.setText(tituloTela);
        this.shell.setLayout(new GridLayout(1, false));
        this.fontText = new Font(shell.getDisplay(), new FontData("Arial", 28, SWT.NORMAL));
        this.fontLabel = new Font(shell.getDisplay(), new FontData("Arial", 13, SWT.NORMAL));
        this.criaCampos();
        this.shell.pack();
        this.centralizaTela();
        this.shell.open();
        while (!shell.isDisposed()) {
            if (!display.isDisposed() && !display.readAndDispatch()) {
                display.sleep();
            }
        }
    }

你能帮我解决这个问题吗? 或者展示在 SWT 中关闭窗口的最佳方式? 谢谢!

【问题讨论】:

    标签: java shell swt dispose


    【解决方案1】:

    为了解决我的问题,我在线程中分离了进程。

    【讨论】:

      【解决方案2】:

      我认为您需要添加“display.dispose();”在你循环!shell.isDisposed() 之后。如下:

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

      【讨论】:

        【解决方案3】:

        您不需要Consulta 类中的while 循环,因为ShellVenda 的子级。这意味着子shell的显示对象与其父shell相同;因此,在您的构造中,在此显示上运行 readAndDispatch() 会被处理两次。

        【讨论】:

          猜你喜欢
          • 2015-10-04
          • 2014-11-08
          • 2017-02-16
          • 1970-01-01
          • 1970-01-01
          • 2019-02-20
          • 2013-02-26
          • 1970-01-01
          • 2016-09-13
          相关资源
          最近更新 更多