Issue
I want to apply horizontal scroll in a Text widget depending of a variable.
I did it this way:
int style = (SWT.BORDER | SWT.V_SCROLL | SWT.CANCEL | SWT.MULTI);
if (!editable) {
style = (style | SWT.READ_ONLY);
}
if (horizontalScroll) {
style = (style | SWT.H_SCROLL);
}
text = new Text(composite, style);
The problem is that horizontal scroll is always present even when horizontalScroll boolean is false. Is not the correct way to do this?
Solution
SWT.CANCEL is not a style supported by the SWT Text widget.
You are unlucky in this case because SWT.CANCEL value equals SWT.H_SCROLL so by adding cancel style you are actually adding the horizontal scroll.
Styles supported by SWT Text Widget: CENTER, ICON_CANCEL, ICON_SEARCH, LEFT, MULTI, PASSWORD, SEARCH, SINGLE, RIGHT, READ_ONLY, WRAP.
Styles supported by inheritance: H_SCROLL, V_SCROLL, BORDER, LEFT_TO_RIGHT, RIGHT_TO_LEFT, FLIP_TEXT_DIRECTION
And you should check that there are some rules that some styles can't go together (ex SWT.SINGLE with SWT.MULTI).
Answered By - BogdanAdrian102