[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.platform.swt] [SWT] curious focus behaviour
|
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();
}
}