Implement Auto-Hide Scrollbar in SWT Text Component
Text textControl = new Text(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); Listener listener = new Listener (){ @Override public void handleEvent(Event event) { Text t = (Text)event.widget; Rectangle r1 = t.getClientArea(); Rectangle r2 = t.computeTrim(r1.x, r1.y, r1.width, r1.height); Point p = t.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); t.getHorizontalBar().setVisible(r2.width <= p.x); t.getVerticalBar().setVisible(r2.height <= p.y); if (event.type == SWT.Modify){ t.getParent().layout(true); t.showSelection(); } }}; textControl.addListener(SWT.Resize, listener); textControl.addListener(SWT.Modify, listener);