Reputation: 669
I'm creating a program in SWT. I have a first Shell that has on it the "add user" button. When you click on the button, a second shell appear. In this case the first shell is still cliccable and focusable. I cannot understand how to avoid that the first shell is focusable until the second has been closed.
This behavior is the default behavior of the dialogs, but I want to have the same behavior with shells. Do you know how can I obtain that?
The code I use to open the second shell is this:
Display display = Menu.this.getDisplay();
AddEditUser shell = new AddEditUser(display);
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
Thankyou
I follow your suggestions, and now the behavior is ok, but now the second shell does not have the top bar as shown in the picture.
Upvotes: 2
Views: 3411
Reputation: 13974
Use SWT.SYSTEM_MODAL
or SWT.APPLICATION_MODAL
for second shells style
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();
}
}
Upvotes: 1