在Java Swing中设置特定组件的工具提示延迟时间 [英] Set the Tooltip Delay Time for a Particular Component in Java Swing

查看:118
本文介绍了在Java Swing中设置特定组件的工具提示延迟时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 JEditorPane 上设置工具提示。我用来确定要显示的工具提示文本的方法是CPU密集型的 - 所以我想只在鼠标停止很短的时间后显示它 - 比如1秒。

I'm trying to set tooltips on a JEditorPane. The method which I use to determine what tooltip text to show is fairly CPU intensive - and so I would like to only show it after the mouse has stopped for a short amount of time - say 1 second.

我知道我可以使用 ToolTipManager.sharedInstance()。setInitialDelay(),但这会立即设置所有swing组件上工具提示的延迟时间我不希望这样。

I know I can use ToolTipManager.sharedInstance().setInitialDelay(), however this will set the delay time for tooltips on all swing components at once and I don't want this.

推荐答案

好吧,我建议在另一个线程上执行CPU密集型任务,这样就不会t中断正常的GUI任务。

Well, I would recommend doing the CPU intensive task on another thread so it doesn't interrupt normal GUI tasks.

这将是一个更好的解决方案。 (而不是试图规避问题)

That would be a better solution. (instead of trying to circumvent the problem)

*编辑* 您可以计算 JEditorPane 并将它们存储在 Map 中。然后你要做的就是从 Map 中访问tootip,如果它发生了变化。

*Edit* You could possibly calculate the tootips for every word in the JEditorPane and store them in a Map. Then all you would have to do is access the tootip out of the Map if it changes.

理想情况下,人们赢了不要移动鼠标并同时打字。因此,您可以在文本更改时计算出tootlips,只需从 mouseMoved()上的 Map 中提取它们。

Ideally people won't be moving the mouse and typing at the same time. So, you can calculate the tootlips when the text changes, and just pull them from the Map on mouseMoved().

这篇关于在Java Swing中设置特定组件的工具提示延迟时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆