Vlad Ilie
Vlad Ilie

Reputation: 1409

new SWT Shell without taking focus?

currently developing an Eclipse plugin and I wanted to make a Shell that does not take focus while it's being created/shown.

I've tried using SWT.NO_FOCUS but to no avail.

How do you create a Shell without taking focus away from another app/window you are on?

Upvotes: 1

Views: 1129

Answers (2)

Baz
Baz

Reputation: 36884

The code below will open a new Shell without taking the focus off the parent:

final Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("StackOverflow");
shell.setLayout(new GridLayout());

Button button = new Button(shell, SWT.PUSH);
button.setText("Open new Shell");
button.addListener(SWT.Selection, (event) -> {
    Shell child = new Shell(shell);
    child.setText("Child");
    child.setVisible(true);
    child.setSize(300,200);
});

shell.pack();
shell.open();

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

Upvotes: 4

greg-449
greg-449

Reputation: 111142

For something like a tooltip shell use:

new Shell(parent, SWT.ON_TOP | SWT.TOOL | SWT.NO_FOCUS);

Upvotes: 1

Related Questions