final int [] events = new int[] {SWT.MouseExit, SWT.MouseHover, SWT.MouseMove, SWT.MouseDown, SWT.DragDetect}; final Listener[] listener = new Listener[1]; listener[0] = new Listener() { public void handleEvent(Event event) { switch (event.type) { case SWT.MouseHover: case SWT.MouseMove: if (updateToolTip(event.x, event.y, label)) break;  case SWT.MouseExit: case SWT.MouseDown: case SWT.DragDetect: for (int i = 0; i < events.length; i++) { removeListener(events[i], listener[0]); } tip.dispose(); tipShowing = false; break; } } }; for (int i = 0; i < events.length; i++) { addListener(events[i], listener[0]); } tipShowing = true; tip.setVisible(true);
void showToolTip (int x, int y) {	final Shell tip = new Shell (getShell(), SWT.ON_TOP);	final Label label = new Label (tip, SWT.CENTER);	Display display = tip.getDisplay();	label.setForeground (display.getSystemColor (SWT.COLOR_INFO_FOREGROUND));	label.setBackground (display.getSystemColor (SWT.COLOR_INFO_BACKGROUND));		if (!updateToolTip(x, y, label)) {		tip.dispose();		return;	}		final int [] events = new int[] {SWT.MouseExit, SWT.MouseHover, SWT.MouseMove, SWT.MouseDown, SWT.DragDetect};	final Listener[] listener = new Listener[1];	listener[0] = new Listener() {		public void handleEvent(Event event) {			switch (event.type) {				case SWT.MouseHover:				case SWT.MouseMove:					if (updateToolTip(event.x, event.y, label)) break;					// FALL THROUGH				case SWT.MouseExit:				case SWT.MouseDown:				case SWT.DragDetect:					for (int i = 0; i < events.length; i++) {						removeListener(events[i], listener[0]);					}					tip.dispose();					tipShowing = false;					break;			}		}	};	for (int i = 0; i < events.length; i++) {		addListener(events[i], listener[0]);	}	tipShowing = true;	tip.setVisible(true);}