[英]Widget is disposed
Good Mourning everybody 大家好
I have a main screen, with follows keybindings: 我有一个主屏幕,具有以下键绑定:
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;
}
}
});
When push F12, search's screen is opened. 按F12键时,将打开搜索屏幕。 Constructor of sale screen:
销售屏幕的构造:
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();
}
}
}
When push F3 on sale screen, the search screen is opened. 在销售屏幕上按F3键时,将打开搜索屏幕。 My problem is: When sale screen is opened the first time, the search screen works normally, but if sale screen is closed and opened again, the search screen didn´t works, casting the error: Widget is disposed.
我的问题是:第一次打开销售屏幕时,搜索屏幕可以正常工作,但是如果关闭销售屏幕并再次打开,则搜索屏幕无法正常工作,从而导致错误:放置了小部件。 The error happen on line 02, in the source code follows.
错误发生在源代码中的第02行。 The variable "abreFechaCaixa" verify if sale screen should be open.
变量“ 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");
}
});
}
Constructor's search screen: 构造函数的搜索屏幕:
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();
}
}
}
Can you help me solve this problem? 您能帮我解决这个问题吗? Or show the best way to close windows in SWT?
还是显示关闭SWT中的窗口的最佳方法? Thanks!
谢谢!
为了解决我的问题,我将进程分成线程。
I think you need to add "display.dispose();" 我认为您需要添加“ display.dispose();” after you while loop for !shell.isDisposed().
在while循环!shell.isDisposed()之后。 Like following:
如下所示:
while (!shell.isDisposed()) {
if (!display.readAndDispatch()){
display.sleep();
}
}
display.dispose ();
You do not need the while
loop in the Consulta
class, as the Shell
is a child of Venda
. 您不需要在
Consulta
类中使用while
循环,因为Shell
是Venda
的子级。 This means that the display object of the child shell is the same as its parent; 这意味着子shell的显示对象与其父对象相同。 in your construction, running
readAndDispatch()
over this display is therefore handled twice. 因此,在您的构造中,在此显示上运行
readAndDispatch()
会被处理两次。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.