tags:

views:

25

answers:

1

In Swing you can get "the other Component involved in this focus change" from this: getOppositeComponent. There does not seem to be a similar call in SWT, does anyone have a workaround or fix for this?

TIA

+1  A: 

There is no equivalent for that in SWT, but you can try to use the following lists on both components:

public class OppositeAwareFocusListener implements FocusListener {
  Widget opposite;
  public void focusGained(FocusEvent e) {
    ..
  }
  public void focusLost(FocusEvent e) {
    this.opposite = e.widget;
  }
}
Eugene Kuleshov
Exactly: you should instead have a `FocusListener` on the widget you wish to observe lost focus.
Paul Lammertsma
Unfortunately, the algorithm is in focusLost(...) so this will not help.
javamonkey79
You can move that code into the focusGained() where you have access to both widgets.
Eugene Kuleshov
But then what happens when the user clicks somewhere outside of the program? Or even in the program but not on a specific widget (e.g. a Composite)? The widget has lost focus and no one else has fired the focus gained event - thus no validation.
javamonkey79