Set custom duration for tooltips in JAVAFX

感情迁移 提交于 2021-01-21 11:22:29

问题


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.

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?

Thanks in advance!


回答1:


In JavaFX 9 you can set the showDuration (and showDelay) property:

tooltip.setShowDuration(Duration.seconds(10));

or in FXML

<Tooltip text="Some text">
    <showDuration>
        <Duration millis="10000" />
    </showDuration>
</Tooltip>

You can also configure this using CSS: the following

.tooltip {
    -fx-show-duration: 10s ;
}

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.)

There is no API for this in earlier versions of JavaFX.



来源:https://stackoverflow.com/questions/46408538/set-custom-duration-for-tooltips-in-javafx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!