java 如何在 JavaFX 按钮上设置工具提示?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37542955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set a tooltip on a JavaFX Button?
提问by Raffaele Sassano
How can I set a title or a text that appears above a button when I hover it with the mouse?
当我用鼠标悬停按钮时,如何设置显示在按钮上方的标题或文本?
回答by DVarga
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.
您还可以自定义您的Tooltip
s: CSS Reference for Tooltip。
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);
回答by ankur_kachru
To add a tooltip in FXML, you could also do this,
要在 FXML 中添加工具提示,您也可以这样做,
<Button>
<tooltip><Tooltip text="my tooltip" /></tooltip>
</Button>
回答by TM00
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. You can then specify various properties (Right panel) of the tooltip like style and text just as you would a normal Node.
如果您使用的是 Scenebuilder,您可以通过在 Miscellaneous 下拉列表(左面板)下找到“Tooltip”并将其拖到要安装工具提示的节点来添加工具提示。然后,您可以指定工具提示的各种属性(右侧面板),如样式和文本,就像您在普通 Node.js 中一样。