I am opening an Swt dialog. But before my application , plugins are loaded and the dialog is opened, if the user clicks on some other background application then in this case the focus is not on my newly created dialog. This can be noted because the header of my dialog is greyed out and if i type anything from keyboard, it is captured in other opened application. My query is how can I get the focus back to my Swt shell/dialog as soon as it is opened.
Thanks!
You can't force the widget focus, as its is managed by OS, but you can request it:
Call below method forceActive
You can pass dialog shell
public static void forceActive(final Shell shell) {
shell.getDisplay().asyncExec(new Runnable() {
public void run() {
if (shell != null && !shell.isDisposed()) {
shell.forceActive();
}
}
});
}