public class ListModel<T> extends DefaultListModel6<T> {
private static final long serialVersionUID = 1L;
+ /** How long to wait before displaying a tooltip, in milliseconds. */
+ private static final int DELAY_TOOLTIP_MS = 1000;
+
/**
* A filter interface, to check for a condition (note that a Predicate class
* already exists in Java 1.8+, and is compatible with this one if you
list.setModel(this);
- final DelayWorker tooltipWatcher = new DelayWorker(500);
+ final DelayWorker tooltipWatcher = new DelayWorker(DELAY_TOOLTIP_MS);
if (tooltipCreator != null) {
tooltipWatcher.start();
}
fireElementChanged(oldIndex);
fireElementChanged(index);
+ synchronized (tooltipWatcher) {
+ if (tooltip != null) {
+ tooltip.setVisible(false);
+ }
+ tooltip = null;
+ }
+
if (ListModel.this.tooltipCreator != null) {
tooltipWatcher.delay("tooltip",
new SwingWorker<Void, Void>() {
@Override
protected void done() {
- Window oldTooltip = tooltip;
- tooltip = null;
- if (oldTooltip != null) {
- oldTooltip.setVisible(false);
+ synchronized (tooltipWatcher) {
+ if (tooltip != null) {
+ tooltip.setVisible(false);
+ }
+ tooltip = null;
}
if (index < 0
return;
}
- tooltip = newTooltip(index, me);
+ if (popup != null
+ && popup.isShowing()) {
+ return;
+ }
+
+ synchronized (tooltipWatcher) {
+ if (tooltip != null) {
+ tooltip.setVisible(false);
+ }
+ tooltip = newTooltip(index, me);
+ }
}
});
}
list.locationToIndex(e.getPoint()));
}
+ Window oldTooltip = tooltip;
+ tooltip = null;
+ if (oldTooltip != null) {
+ oldTooltip.setVisible(false);
+ }
+
popup.show(list, e.getX(), e.getY());
}
}
newTooltip.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
-
Window promotedTooltip = tooltipCreator
.generateTooltip(value, false);
- promotedTooltip.setLocation(newTooltip.getLocation());
+ if (promotedTooltip != null) {
+ promotedTooltip.setLocation(me.getXOnScreen(),
+ me.getYOnScreen());
+ promotedTooltip.setVisible(true);
+ }
+
newTooltip.setVisible(false);
- promotedTooltip.setVisible(true);
}
});
- newTooltip.setLocation(me.getXOnScreen(), me.getYOnScreen());
+ newTooltip.setLocation(me.getXOnScreen(), me.getYOnScreen());
newTooltip.setVisible(true);
}