在JavaFX中显示禁用控件上的工具提示
可以在禁用的控件上显示工具提示吗?
It is possible to show a Tooltip on a disabled Control?
我有以下代码,但这不起作用:
I have the following code and this doesn't work:
txt_searchText.setDisable(true);
txt.searchText.setTooltip(new Tooltip("Message"));
有没有人能解决这个问题?
Has anyone a solution for that problem?
Thx
答案是否定的。目前您无法在禁用的节点上显示工具提示,原因很简单,禁用的节点不会收到任何MouseEvents。
The answer is no. Currently you cannot show a tooltip on disabled Node, for the simple reason that disabled Nodes do not receive any MouseEvents.
您可以在官方问题跟踪器中看到问题这里(要求登录): https://javafx-jira.kenai.com/browse/RT-28850
You can see the issue being raised in the official issue tracler here (require login) : https://javafx-jira.kenai.com/browse/RT-28850
您的问题的一个解决方案可能是将您的Control包装成其他内容。
One solution to your problem could be to wrap your Control into something else.
例如,put您可以控制另一个Control,例如SplitPane或Label。然后,您可以将工具提示应用于该包装并禁用您的第一个控件。
For example, put your control into another Control, like a SplitPane or a Label. Then you could apply your tooltip to that wrapper and disable your first control.