Display display = getDisplay(); display.asyncExec(new Runnable() { public void run() { if (table.isDisposed()) return; int oldRow = row; row = -1; int count = table.getItemCount(); if (count == 0) { resize(); } else { setRowColumn(oldRow == 0 ? 0 : oldRow -1, column, true); } } });
row = null; column = null; resize();
public TableCursor(Table parent, int style) {	super(parent, style);	table = parent;	setBackground(null);	setForeground(null);		Listener listener = new Listener() {		public void handleEvent(Event event) {			switch (event.type) {				case SWT.Dispose :					dispose(event);					break;				case SWT.FocusIn :				case SWT.FocusOut :					redraw();					break;				case SWT.KeyDown :					keyDown(event);					break;				case SWT.Paint :					paint(event);					break;				case SWT.Traverse :					traverse(event);					break;			}		}	};	int[] events = new int[] {SWT.Dispose, SWT.FocusIn, SWT.FocusOut, SWT.KeyDown, SWT.Paint, SWT.Traverse};	for (int i = 0; i < events.length; i++) {		addListener(events[i], listener);	}	tableListener = new Listener() {		public void handleEvent(Event event) {			switch (event.type) {				case SWT.MouseDown :					tableMouseDown(event);					break;				case SWT.FocusIn :					tableFocusIn(event);					break;			}		}	};	table.addListener(SWT.FocusIn, tableListener);	table.addListener(SWT.MouseDown, tableListener);	disposeItemListener = new Listener() {		public void handleEvent(Event event) {			Display display = getDisplay();			display.asyncExec(new Runnable() {				public void run() {					if (table.isDisposed()) return;					int oldRow = row;					row = -1;					int count = table.getItemCount();					if (count == 0) {						resize();					} else {						setRowColumn(oldRow == 0 ? 0 : oldRow -1, column, true);					}				}			});		}	};	disposeColumnListener = new Listener() {		public void handleEvent(Event event) {			Display display = getDisplay();			display.asyncExec(new Runnable() {				public void run() {					if (table.isDisposed()) return;					int oldColumn = column;					column = -1;					setRowColumn(row, oldColumn == 0 ? 0 : oldColumn-1, true);				}			});		}	};	resizeListener = new Listener() {		public void handleEvent(Event event) {			resize();		}	};	ScrollBar hBar = table.getHorizontalBar();	if (hBar != null) {		hBar.addListener(SWT.Selection, resizeListener);	}	ScrollBar vBar = table.getVerticalBar();	if (vBar != null) {		vBar.addListener(SWT.Selection, resizeListener);	}}