问题描述
我正在寻找以下问题的解决方案:我用SceneBuilder
建立了javafx GUI
并将tooltips
添加到了我添加的一些标签中.
I'm looking for a solution for the following problem:I've built up a javafx GUI
with SceneBuilder
and added tooltips
to some of the labels I added.
但是,tooltips
会在约5秒钟后自动隐藏.有时,这不足以让用户阅读tooltips
整个内容.只要光标停留在标签上方并完全禁用此autoHide
功能,我想显示tooltip
.
However, the tooltips
automatically hide after ~5 seconds. Sometimes this is not enough for the user to read the tooltips
whole content. I would like to show the tooltip
as long as the cursor stays above the label and completely disable this autoHide
function.
我没有找到自定义弹出窗口显示时间或完全禁用自动隐藏功能的方法.有人解决了这个或类似的问题吗?
I did not find a way to customize the time a popup is shown or how to disable the auto hide function completely.Has somebody solved this or a similar problem?
提前谢谢!
推荐答案
在JavaFX 9中,您可以设置 showDuration
(和showDelay
)属性:
In JavaFX 9 you can set the showDuration
(and showDelay
) property:
tooltip.setShowDuration(Duration.seconds(10));
或在FXML中
<Tooltip text="Some text">
<showDuration>
<Duration millis="10000" />
</showDuration>
</Tooltip>
您还可以使用CSS进行配置:
You can also configure this using CSS: the following
.tooltip {
-fx-show-duration: 10s ;
}
外部CSS文件中的
会将所有工具提示的显示持续时间设置为10秒. (显然,您可以在工具提示上设置样式类和/或ID,以创建更具体的CSS选择器.)
in an external CSS file will set the show duration to 10 seconds for all tooltips. (And obviously you can set style classes and/or ids on the tooltip to create more specific CSS selectors.)
JavaFX的早期版本中没有针对此的API.
There is no API for this in earlier versions of JavaFX.
这篇关于在JAVAFX中设置工具提示的自定义持续时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!