import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.layout.*; import org.eclipse.swt.widgets.*; /** * @author Thomas Singer */ public class ScrollTest { 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.DOUBLE_BUFFERED | SWT.V_SCROLL); final ScrollBar verticalBar = composite.getVerticalBar(); verticalBar.setValues(420, 0, 1002, 24, 1, 24); composite.addListener(SWT.Paint, event -> { int selection = verticalBar.getSelection(); final Rectangle bounds = composite.getBounds(); final int rowHeight = event.gc.getFontMetrics().getHeight(); while (bounds.height > 0) { event.gc.drawString(Integer.toString(selection++), bounds.x, bounds.y); bounds.y += rowHeight; bounds.height -= rowHeight; } }); verticalBar.addListener(SWT.Selection, event -> composite.redraw()); final Table table = new Table(shell, SWT.BORDER | SWT.V_SCROLL | SWT.VIRTUAL); table.addListener(SWT.SetData, event -> ((Item)event.item).setText("Row " + event.index)); table.setItemCount(1002); table.setSelection(420); shell.setSize(500, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); } }