|
|
|
|
Re: Problem to give back focus to the main shell [message #465307 is a reply to message #465131] |
Thu, 08 December 2005 21:30 |
Veronika Irvine Messages: 1272 Registered: July 2009 |
Senior Member |
|
|
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();
> }
> }
>
>
>
>
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02648 seconds