public static void main(String[] args) { final Display display = new Display(); final Image image = new Image(display, 16, 16); GC gc = new GC(image); gc.setBackground(display.getSystemColor(SWT.COLOR_RED)); gc.fillRectangle(image.getBounds()); gc.dispose(); final Shell shell = new Shell(display); shell.setText("Lazy Table"); shell.setLayout(new FillLayout()); final Table table = new Table(shell, SWT.BORDER | SWT.MULTI); table.setSize(200, 200); Thread thread = new Thread() { @Override public void run() { for (int i = 0; i < 20000; i++) { if (table.isDisposed()) return; final int[] index = new int[] {i}; display.syncExec( () -> { if (table.isDisposed()) return; TableItem item = new TableItem(table, SWT.NONE); item.setText("Table Item " + index[0]); item.setImage(image); }); } } }; thread.start(); shell.setSize(200, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } image.dispose(); display.dispose(); }
protected String[] getAuthenticationDialog(final String realm, final String location) { final Display display = SWTThread.getInstance().getDisplay(); if (display.isDisposed()) { return (null); } final AESemaphore sem = new AESemaphore("SWTAuth"); final authDialog[] dialog = new authDialog[1]; TOTorrent torrent = TorrentUtils.getTLSTorrent(); final boolean is_tracker; final String details; if (torrent == null) { is_tracker = false; details = TorrentUtils.getTLSDescription(); } else { details = TorrentUtils.getLocalisedName(torrent); is_tracker = true; } try { if (display.getThread() == Thread.currentThread()) { dialog[0] = new authDialog(sem, display, realm, is_tracker, location, details); while (!(display.isDisposed() || sem.isReleasedForever())) { if (!display.readAndDispatch()) { display.sleep(); } } if (display.isDisposed()) { return (null); } } else { display.asyncExec( new AERunnable() { public void runSupport() { dialog[0] = new authDialog(sem, display, realm, is_tracker, location, details); } }); } } catch (Throwable e) { Debug.printStackTrace(e); return (null); } sem.reserve(); String user = dialog[0].getUsername(); String pw = dialog[0].getPassword(); String persist = dialog[0].savePassword() ? "true" : "false"; if (user == null) { return (null); } return (new String[] {user, pw == null ? "" : pw, persist}); }