import org.eclipse.swt.*; import org.eclipse.swt.layout.*; import org.eclipse.swt.widgets.*; /** * @author Thomas Singer */ public class LazyTableLoading { public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final Table table = new Table(shell, SWT.BORDER | SWT.V_SCROLL); table.setHeaderVisible(true); final TableColumn column = new TableColumn(table, SWT.LEFT); column.setText("Column"); column.setWidth(150); for (int i = 0; i < 4; i++) { createItem(table); } final boolean[] loading = new boolean[1]; table.addListener(SWT.Paint, new Listener() { @Override public void handleEvent(Event event) { if (table.isDisposed()) { return; } if (!shouldLoad()) { return; } if (loading[0]) { return; } loading[0] = true; display.timerExec(1000, () -> { for (int i = 0; i < 50; i++) { if (table.getItemCount() == 300) { break; } createItem(table); } loading[0] = false; }); } private boolean shouldLoad() { final ScrollBar scrollBar = table.getVerticalBar(); if (!scrollBar.isVisible()) { return true; } final int maximum = scrollBar.getMaximum(); if (maximum == 0) { return true; } final int scrollBarPosition = scrollBar.getSelection() + scrollBar.getThumb(); System.out.println(scrollBarPosition + " of " + maximum); return scrollBarPosition > maximum * 0.75; } }); shell.setSize(400, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); } private static void createItem(Table table) { final TableItem item = new TableItem(table, SWT.LEFT); item.setText(0, "Row " + table.getItemCount()); } }