[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.platform.swt] Re: [SWT] curious focus behaviour
|
Andre,
#setFocus will set the focus in a platform-appropriate way, so this can
reveal differences between win32 and motif for instance (though it should
never cause a StackOverflow, unless it's a result of you having a focus-in
listener who reassigns focus elsewhere but the platform puts it in the
same place, thereby re-notifying your focus-in listener again, etc.).
#forceFocus should really force focus to the specified widget, so there
should not be a platform difference if you use this. If you have a simple
test case that shows this behaving inconsistently then please log a bug
report with Platform - SWT.
Grant
Andre wrote:
> hello..
> I recently stumbled over some curious focus behaviour:
> if I call a widget's forceFocus() or setFocus() method, it works fine on
> SWT.WIN32 (XP) but doesn't on SWT.motif (Linux and Solaris) and SWT.photon
> (QNX). On SWT.gtk (Linux) it even may cause a stack overflow.
> My questions are: is that a bug or is that _really_ a platform specific
> behaviour? Is there I way to realy force a widget to get the focus - on
> every platform? I thought that if it's part of the API it should work
> everywhere..
> Thanks in advance
> Andre
> PS: a short sample code that demonstrates this problem:
> public class CuriousFocus
> {
> public static void main(String[] args)
> {
> Display display = new Display();
> Shell shell = new Shell(display);
> final Canvas widget1 = new Canvas(shell, SWT.BORDER);
>
widget1.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
> widget1.addFocusListener( new FocusListener()
> {
> public void focusGained(FocusEvent e)
> {
> System.out.println("widget1::focusGained()");
>
widget1.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
> widget1.redraw();
> }
> public void focusLost(FocusEvent e)
> {
> System.out.println("widget1::focusLost()");
>
widget1.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
> widget1.redraw();
> }
> });
> final Canvas widget2 = new Canvas(shell, SWT.BORDER);
>
widget2.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
> widget2.addFocusListener( new FocusListener()
> {
> public void focusGained(FocusEvent e)
> {
> System.out.println("widget2::focusGained() \n");
>
widget2.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
> widget2.redraw();
> }
> public void focusLost(FocusEvent e)
> {
> System.out.println("widget2::focusLost()");
>
widget2.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
> widget2.redraw();
> // grab keyboard focus forever here
> widget2.forceFocus();
> //widget2.setFocus();
> }
> });
> shell.setLayout( new FillLayout());
> shell.open();
> //shell.setSize(200, 100);
> shell.pack();
> while (!shell.isDisposed())
> {
> if (!display.readAndDispatch())
> {
> display.sleep();
> }
> }
> display.dispose();
> }
> }