在JAVAFX中设置工具提示的自定义持续时间 [英] Set custom duration for tooltips in JAVAFX

查看:245
本文介绍了在JAVAFX中设置工具提示的自定义持续时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找以下问题的解决方案: 我用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中,您可以设置

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中设置工具提示的自定义持续时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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