From: Niki Roo Date: Fri, 1 May 2020 09:57:01 +0000 (+0200) Subject: ListModel: fix tooltip delay X-Git-Tag: fanfix-swing-1.1.0~31 X-Git-Url: http://git.nikiroo.be/?a=commitdiff_plain;h=f8ad84a175bfae3010b55139358c07048d167956;p=fanfix-swing.git ListModel: fix tooltip delay --- diff --git a/src/be/nikiroo/utils/ui/ListModel.java b/src/be/nikiroo/utils/ui/ListModel.java index cf16d5f0..3029f61a 100644 --- a/src/be/nikiroo/utils/ui/ListModel.java +++ b/src/be/nikiroo/utils/ui/ListModel.java @@ -34,6 +34,9 @@ import be.nikiroo.utils.compat.ListCellRenderer6; public class ListModel extends DefaultListModel6 { 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 @@ -254,7 +257,7 @@ public class ListModel extends DefaultListModel6 { list.setModel(this); - final DelayWorker tooltipWatcher = new DelayWorker(500); + final DelayWorker tooltipWatcher = new DelayWorker(DELAY_TOOLTIP_MS); if (tooltipCreator != null) { tooltipWatcher.start(); } @@ -272,6 +275,12 @@ public class ListModel extends DefaultListModel6 { hoveredIndex = index; fireElementChanged(oldIndex); fireElementChanged(index); + + Window oldTooltip = tooltip; + tooltip = null; + if (oldTooltip != null) { + oldTooltip.setVisible(false); + } if (ListModel.this.tooltipCreator != null) { tooltipWatcher.delay("tooltip", @@ -284,12 +293,6 @@ public class ListModel extends DefaultListModel6 { @Override protected void done() { - Window oldTooltip = tooltip; - tooltip = null; - if (oldTooltip != null) { - oldTooltip.setVisible(false); - } - if (index < 0 || index != hoveredIndex) { return;