import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.layout.*; import org.eclipse.swt.widgets.*; public class AutohidingScrollbar { public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final Composite composite = new Composite(shell, SWT.V_SCROLL); composite.getVerticalBar().setValues(0, 0, 1000, 10, 1, 10); composite.addListener(SWT.Paint, event -> { final Rectangle area = composite.getClientArea(); final String string = "hello world"; final int stringWidth = event.gc.stringExtent(string).x; event.gc.drawString(string, area.x + area.width - stringWidth, area.y); }); shell.setSize(400, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); } }