2010-07-26 10 views
0

Good Mourning tout le mondeWidget est disposé

J'ai un écran principal, avec 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; 
     }    
    } 
}); 

Lorsque poussée F12, l'écran de recherche est ouvert. Constructeur de l'écran de vente:

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(); 
      } 
     } 
    } 

Lorsque vous appuyez sur F3 en écran de vente, l'écran de recherche est ouvert. Mon problème est: Lorsque l'écran de vente est ouvert la première fois, l'écran de recherche fonctionne normalement, mais si l'écran de vente est fermé et ouvert à nouveau, l'écran de recherche n'a pas fonctionné, en jetant l'erreur: Widget est éliminé. L'erreur se produit sur la ligne 02, dans le code source suit. La variable "abreFechaCaixa" vérifie si l'écran de vente doit être ouvert.

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"); 
    } 
    }); 
} 

écran de recherche de constructeur:

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(); 
      } 
     } 
    } 

Pouvez-vous me aider à résoudre ce problème? Ou montrer le meilleur moyen de fermer les fenêtres dans SWT? Merci!

Répondre

0

Je pense que vous devez ajouter "display.dispose();" après que vous bouclez pour! shell.isDisposed(). Comme suit:

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

Pour résoudre mon problème, j'ai séparé le processus dans les threads.

0

Vous n'avez pas besoin de la boucle while dans la classe Consulta, car Shell est un enfant de Venda. Cela signifie que l'objet d'affichage du shell enfant est le même que son parent; Dans votre construction, exécuter readAndDispatch() sur cet affichage est donc géré deux fois.