简体   繁体   English

如何在JavaFX Button上设置工具提示?

[英]How to set a tooltip on a JavaFX Button?

当我用鼠标悬停按钮时,如何设置按钮上方显示的标题或文字?

The Tooltip class is what you are looking for. Tooltip类正是您所需要的。

Example for a simple Tooltip 简单工具提示的示例

Button button = new Button("Hover Me");
button.setTooltip(new Tooltip("Tooltip for Button"));

在此输入图像描述

You can also customize your Tooltip s: CSS Reference for Tooltip . 您还可以自定义TooltipTooltipCSS参考

Example for a styled Tooltip 样式化工具提示的示例

Button button = new Button();
button.setText("Hover Me!");
Tooltip tt = new Tooltip();
tt.setText("Text on Hover");
tt.setStyle("-fx-font: normal bold 4 Langdon; "
    + "-fx-base: #AE3522; "
    + "-fx-text-fill: orange;");

button.setTooltip(tt);

在此输入图像描述

To add a tooltip in FXML, you could also do this, 要在FXML中添加工具提示,您也可以这样做,

<Button>
 <tooltip><Tooltip text="my tooltip" /></tooltip>
</Button>

If you are using Scenebuilder, you can add tooltips by locating "Tooltip" under the Miscellaneous dropdown (Left panel) and dragging it to the node you want to install the tooltip. 如果您使用的是Scenebuilder,则可以通过在“杂项”下拉列表(左侧面板)下找到“工具提示”并将其拖动到要安装工具提示的节点来添加工具提示。 You can then specify various properties (Right panel) of the tooltip like style and text just as you would a normal Node. 然后,您可以像使用普通节点一样指定工具提示的各种属性(右侧面板),如样式和文本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM