I have a strange issue: there is a SectionPart with composite, which is create from FormToolkit#createComposite(getSection()). Composite contains some number of widgets, which are positioned vertically one under other (as in a usual form). When the cursor is inside some widget, let’s say input filed and I am clicking right between two fields on empty space, then focus automatically jumps to the first field in this composite.
I’ve tried to set SWT.NO_FOCUS style bit to the first widget in the form (usually it is a TableComboViewer) but it didn’t helped (it seems, that this bit is not set on TableCombo, which is inside TableComboViewer).
So, have anybody faced something similar, or are there any workarounds for this problem or any clues what could it be?
Upd1: setting NO_FOCUS style helps for non TableComboViewer widgets (in this case they are not receiving focus). In case of TableComboViewer TableCombo widget contains Text widget, which receives focus, but even, if I add NO_FOCUS bit, it is not applied to Text style. I’ve checked source of TableCombo and there is a method checkStyle, which does following:
private static int checkStyle (int style) {
int mask = SWT.BORDER | SWT.READ_ONLY | SWT.FLAT | SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
return SWT.NO_FOCUS | (style & mask);
}
I am not actually sure what it does, cause I am not really good in bitwise operation, but seems, that this is the problem, why I can’t set NO_FOCUS flag.
I don’t understand though, why when I am clicking on Composite, it tries to set foxus on it’s children, can I somehow suppress this?
Upd2: The reason is probably found, it is said, that:
When the view is activated, focus is transferred to the form, which passes it to the first control capable of accepting focus, our link in this case.
And it seems, that it is not possible to forbid this.
Thanks in advance,
AlexG
You problem lies in
Composite.setFocus().. have a look at this:As you can see, this will try to set the focus on the first control in the composite that will allow for the focus…
[EDIT – the following is added to clarify…]
The above method would not be a problem if it wasn’t for the
MouseListenerthat is installed on allCompositesinFormToolkit.adapt(Composite composite):I have solved this problem on a number of occasions by having my own
FormToolkit.adapt(Composite composite)in a sub-class that does the right thing – I just exchangesetFocus()withforceFocus(). Though that can occasionally give you other problems…