So I want to have a delay in my tooltip to close it when mouse exit, lets say 1 second example, and if you have returned in that 1 second to tooltipShell you dont close tooltip. Is this possible and how should I do it if it is?
Code
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.PointerInfo;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
public class Linkki {
private static Listener listener = new MouseEnterExitListener();
public static Shell shell;
public static void main(String[] args) {
Display display = new Display();
shell = new Shell(display);
Label label = new Label(shell, SWT.SHADOW_IN | SWT.CENTER);
label.setText("Point your cursor here ...");
label.setBounds(10, 10, 200, 15);
label.addListener(SWT.MouseEnter, listener);
label.addListener(SWT.MouseExit, listener);
shell.setSize(260, 120);
shell.open();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
}
class MouseEnterExitListener implements Listener {
private static Shell tooltipShell;
private static Label tooltipLabel;
public void handleEvent(Event e) {
switch (e.type) {
case SWT.MouseEnter:
if(tooltipShell!=null && !tooltipShell.isDisposed())
tooltipShell.dispose();
tooltipShell = new Shell(Linkki.shell, SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);
FillLayout layout = new FillLayout();
layout.marginWidth = 5;
tooltipShell.setLayout(layout);
tooltipLabel = new Label(tooltipShell, SWT.NONE);
tooltipLabel.setText("kek");
tooltipShell.pack();
PointerInfo a = MouseInfo.getPointerInfo();
Point b = a.getLocation();
int x = (int) b.getX();
int y = (int) b.getY();
tooltipShell.setLocation(x-10, y-10);
tooltipShell.setVisible(true);
tooltipShell.addListener(SWT.MouseExit, new Listener() {
public void handleEvent(Event e) {
tooltipShell.dispose();
tooltipShell = null;
tooltipLabel = null;
}
});
break;
}
}
}