@Plamen: great solution. I had the same problem, but for multi-line text with SWT.WRAP style without horizontal scrollbar.
I had to change a few things to do it right:
Text text = new Text(parent, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL); Listener scrollBarListener = new Listener (){ @Override public void handleEvent(Event event) { Text t = (Text)event.widget; Rectangle r1 = t.getClientArea(); // use r1.x as wHint instead of SWT.DEFAULT Rectangle r2 = t.computeTrim(r1.x, r1.y, r1.width, r1.height); Point p = t.computeSize(r1.x, SWT.DEFAULT, true); t.getVerticalBar().setVisible(r2.height <= py); if (event.type == SWT.Modify){ t.getParent().layout(true); t.showSelection(); } }}; text.addListener(SWT.Resize, scrollBarListener); text.addListener(SWT.Modify, scrollBarListener);
source share