Focus is always in exactly one place, so if it's in a Text within a Shell
then the Shell is not the focus control. It's common to say the shell has
focus relative to other shells, but technically it's active, not focused.
The snippet:
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setBounds(10,10,200,200);
final Text text1 = new Text(shell, SWT.SINGLE);
text1.setBounds(10,10,100,30);
final Text text2 = new Text(shell, SWT.SINGLE);
text2.setBounds(10,50,100,30);
Listener listener = new Listener() {
public void handleEvent(Event event) {
System.out.println("-------");
System.out.println("text1 isFocusControl: " +
text1.isFocusControl());
System.out.println("text2 isFocusControl: " +
text2.isFocusControl());
System.out.println("shell isFocusControl: " +
shell.isFocusControl());
}
};
display.addFilter(SWT.FocusIn, listener);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
Grant
"Wayne Beaton" <wayne@xxxxxxxxxxx> wrote in message
news:1213105976.26171.15.camel@xxxxxxxxxx
I was thinking about this last night (but was too lazy to boot up).
Doesn't the shell have focus as long as anything it contains has focus?
The only time I've ever used this trick, I only had a shell (that I drew
on via a PaintListener).
I suppose I could set up a little test... (but apparently last evening's
laziness is still with me)
Wayne
On Mon, 2008-06-09 at 15:02 -0400, Grant Gayed wrote:
I think Deactivate is a better listener to hook on the Shell, to more
easily
indicate whether focus is anywhere within the shell or not.
Grant
"Wayne Beaton" <wayne@xxxxxxxxxxx> wrote in message
news:1213025476.6185.16.camel@xxxxxxxxxx
Try putting a focus listener on the shell; close it when you lose
focus.
I believe that this should have the effect you're looking for.
HTH,
Wayne
On Mon, 2008-06-09 at 09:43 -0500, Hongying Zhang wrote:
Hello,
I need create a Popup Shell that will be popuped up when mouse click
a
control, and this popup shell has to be resizable with some other
feature; this popup shell also need have a behavior that when the
mouse
clicked outside popup Shell, this popup shell will close (just like
menu
behavior ). Since I cannot subclass SWT Menu widget, so I created my
own
Popup shell class.
Now, I have problem to close it when mouse clicked somewhere outside
the
popup shell. I tried to let the shell listen to mouse up event, but
that
won'y work. Can someone please let me know what should I do to make
this
popup shell close when mouse clicked outside the Shell.
Thanks,
Hongying