2012-02-28 5 views
2

SWTでプログラムを作成しています。私は最初のシェルを持っている "ユーザーの追加"ボタンがあります。 ボタンをクリックすると、2番目のシェルが表示されます。 この場合、最初のシェルはまだクリティカルでフォーカスがあります。私は最初のシェルが2番目が閉じられるまでフォーカス可能であることを回避する方法を理解できません。swtの別のシェルからシェルを閉じるのを待つ方法は?

この動作はダイアログのデフォルトの動作ですが、シェルでも同じ動作が必要です。どうすればそれを得ることができるか知っていますか?

私は第2のシェルを開くために使用したコードはこれです:

Display display = Menu.this.getDisplay(); 
AddEditUser shell = new AddEditUser(display); 
shell.open(); 
shell.layout(); 
while (!shell.isDisposed()) { 
    if (!display.readAndDispatch()) { 
     display.sleep(); 
    } 
} 

ありがとう

私はあなたの提案に従ってください、と今の行動はokですが、今第2のシェルがトップを持っていませんバーが表示されます。 window without top bar

+0

私の更新の答えを参照してください。 – Favonius

答えて

1

使用SWT.SYSTEM_MODALまたはSWT.APPLICATION_MODALと第2のシェル

enter image description here

import org.eclipse.swt.SWT; 
import org.eclipse.swt.events.SelectionAdapter; 
import org.eclipse.swt.events.SelectionEvent; 
import org.eclipse.swt.layout.GridData; 
import org.eclipse.swt.layout.GridLayout; 
import org.eclipse.swt.widgets.Button; 
import org.eclipse.swt.widgets.Display; 
import org.eclipse.swt.widgets.Shell; 


public class ShellTest { 

    public static void main(String[] args) 
    { 
     final Display display = new Display(); 
     final Shell shell = new Shell(display); 
     shell.setLayout(new GridLayout()); 

     Button b = new Button(shell, SWT.PUSH); 
     b.setText("Open Shell"); 
     b.addSelectionListener(new SelectionAdapter() { 
      public void widgetSelected(SelectionEvent e) { 
       openNewShell(shell); 
      } 
     }); 
     shell.setSize(250, 150); 
     shell.open(); 
     while (!shell.isDisposed()) { 
      if (!display.readAndDispatch()) 
       display.sleep(); 
     } 
     display.dispose(); 
    } 

    protected static void openNewShell(final Shell shell) 
    { 
     Shell child = new Shell(shell, SWT.TITLE|SWT.SYSTEM_MODAL| SWT.CLOSE | SWT.MAX); 
     child.setSize(100, 100); 
     child.setLayout(new GridLayout()); 
     child.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 

     child.open(); 
    } 
} 
+0

しかし、私はトップバーを見ることができません。上記の写真を見てください。 – hurtledown

+0

@hurtledown:更新された回答を参照してください。特に、子のシェルコンストラクタです。また、私はあなたにそれらの感触を得るために異なるswtスタイルのビットで遊ぶことをお勧めします。 – Favonius

2

オープン第2シェルスタイルのスタイルSWT.APPLICATION_MODAL

関連する問題