Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining focus in SWT

Tags:

java

swt

I know that I can see if a particular widget has control in SWT by using isFocusControl() on it. However, when my expected widget doesn't have focus, how can I determine what does (in other words, what took the focus away)?

I'm able to handle keyboard events with traverse listeners, but changing focus using clicks of the mouse appears to mystify my application. I can't seem to figure out how to find the item that took the focus from the previous item.

I'm also having issues with reliably setting focus to another widget from within a FocusLost listener if the focus is changed by a mouse event.

Any suggestions?

like image 536
Zoot Avatar asked Jan 07 '11 17:01

Zoot


2 Answers

It is:

Display.getFocusControl();
like image 138
Daniel Avatar answered Nov 20 '22 03:11

Daniel


As explained, Display.getFocusControl() tells you which Control has focus. You can associate information with widgets via the setData() methods. You can do this with every control that could possibly get focus and then getData() should help you figure out what control has the focus.

Otherwise you can just keep pointers to the controls that you created and compare the pointer to your known control pointers, no?

like image 2
stippi Avatar answered Nov 20 '22 01:11

stippi