Problem to give back focus to the main shell [message #465131] |
Tue, 06 December 2005 10:16  |
Eclipse User |
|
|
|
Hi,
I have a problem to give back the focus to my main shell after triggering
the creation of a new shell.
The snippet below illustrates the problem: when clicking on F1, a new
shell is opened, but I can't manage to force the focus back onto the main
shell so that F1 creates yet another shell (other than clicking on the
main shell before).
How can I do this ?
Thanks,
Helene
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class SetFocusProblem {
private static Shell shell;
private static int shellNumbers = 0;
/**
* @param args
*/
public static void main(String[] args) {
Display display = new Display();
shell = new Shell (display);
shell.setLayout(new GridLayout());
shell.open();
shell.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent event) {
if (event.keyCode == SWT.F1) {
System.out.println("Opening new shell");
openNewShell();
shell.setFocus(); // does not work ?
}
}
});
while (!shell.isDisposed ()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose ();
}
protected static void openNewShell() {
Shell newShell = new Shell(shell, SWT.ON_TOP);
newShell.setLayout(new GridLayout());
Label label = new Label(newShell, SWT.NONE);
label.setText("new shell " + shellNumbers++);
label.setLayoutData(new GridData());
newShell.setSize(100, 100);
newShell.open();
}
}
|
|
|
|
|
|
Re: Problem to give back focus to the main shell [message #465307 is a reply to message #465131] |
Thu, 08 December 2005 16:30   |
Eclipse User |
|
|
|
public class SetFocusProblem {
private static Shell shell;
private static int shellNumbers = 0;
/**
* @param args
*/
public static void main(String[] args) {
Display display = new Display();
shell = new Shell (display);
shell.setLayout(new GridLayout());
shell.open();
shell.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent event) {
if (event.keyCode == SWT.F1) {
System.out.println("Opening new shell");
openNewShell();
}
}
});
while (!shell.isDisposed ()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose ();
}
protected static void openNewShell() {
Shell newShell = new Shell(shell, SWT.ON_TOP);
newShell.setLayout(new GridLayout());
Label label = new Label(newShell, SWT.NONE);
label.setText("new shell " + shellNumbers++);
label.setLayoutData(new GridData());
newShell.setSize(100, 100);
// newShell.open(); - this takes focus in newShell - BAD!
newShell.setVisible(true); // this does not take focus in
newShell - GOOD!
}
}
"hortiz" <hortiz@xxxxxxxxxx.xxx> wrote in message
news:701ca867df5061d71192f8a95bc60a28$1@www.eclipse.org...
> Hi,
>
> I have a problem to give back the focus to my main shell after triggering
> the creation of a new shell.
>
> The snippet below illustrates the problem: when clicking on F1, a new
> shell is opened, but I can't manage to force the focus back onto the main
> shell so that F1 creates yet another shell (other than clicking on the
> main shell before).
>
> How can I do this ?
> Thanks,
> Helene
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.events.KeyAdapter;
> import org.eclipse.swt.events.KeyEvent;
> import org.eclipse.swt.layout.GridData;
> import org.eclipse.swt.layout.GridLayout;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Label;
> import org.eclipse.swt.widgets.Shell;
>
> public class SetFocusProblem {
>
> private static Shell shell;
> private static int shellNumbers = 0;
>
> /**
> * @param args
> */
> public static void main(String[] args) {
>
> Display display = new Display();
> shell = new Shell (display);
> shell.setLayout(new GridLayout());
> shell.open();
> shell.addKeyListener(new KeyAdapter() {
> public void keyPressed(KeyEvent event) {
> if (event.keyCode == SWT.F1) {
> System.out.println("Opening new shell");
> openNewShell();
> shell.setFocus(); // does not work ?
> }
> }
> });
> while (!shell.isDisposed ()) {
> if (!display.readAndDispatch()) {
> display.sleep();
> }
> }
> display.dispose ();
> }
> protected static void openNewShell() {
> Shell newShell = new Shell(shell, SWT.ON_TOP);
> newShell.setLayout(new GridLayout());
> Label label = new Label(newShell, SWT.NONE);
> label.setText("new shell " + shellNumbers++);
> label.setLayoutData(new GridData());
> newShell.setSize(100, 100);
> newShell.open();
> }
> }
>
>
>
>
|
|
|
|
Re: Problem to give back focus to the main shell [message #465904 is a reply to message #465339] |
Wed, 21 December 2005 12:04  |
Eclipse User |
|
|
|
I have found a similar issue. However, using win.setVisible(true) vs win.open() doesn't change anything. The dialog still has modal control of Eclipse. In my case I am opening a dialog with an embedded browser. I want the dialog to be beside the parent dialog and above it in Z-order. I want to be able to click in it but it must be non-modal. This works just fine on windows but not on linux with firefox embedded in the dialog.
The follwoing bit of code opens the window:
win = new Shell(this.getShell(), SWT.TOOL);
setWindowSize(NOVICE_WINDOW_WIDTH); // simple setBounds() call
win.setLayout(new FillLayout());
noviceArea = new Composite(win, SWT.NULL);
noviceArea.setBackground(win.getDisplay().getSystemColor(SWT .COLOR_INFO_BACKGROUND));
noviceAreaLayout = new StackLayout();
noviceArea.setLayout(noviceAreaLayout);
blankArea = new Composite(noviceArea, SWT.NULL);
blankArea.setBackground(win.getDisplay().getSystemColor(SWT. COLOR_INFO_BACKGROUND));
textArea = new Browser(noviceArea, SWT.NULL);
textArea.setBackground(win.getDisplay().getSystemColor(SWT.C OLOR_INFO_BACKGROUND));
noviceAreaLayout.topControl = blankArea;
setText(defaultText);
open = true;
layout.topControl = leftButton;
leftButton.setEnabled(false);
layout();
win.setVisible(true); // use of .open() causes focus problem?
this.setFocus(); // set focus back on the parent dialog
This bit of code is actually in a wizard dialog page within Eclipse.
|
|
|
Powered by
FUDForum. Page generated in 0.09287 seconds