Reputation: 1406
This is how I set my tooltips:
if(Globals.isShowTooltips()) {
locale = new Locale(Globals.getGuiLanguage());
bundle = ResourceBundle.getBundle("bundles.lang", locale);
btnSettingsApply.setTooltip(
new Tooltip(bundle.getString("btnSettingsApplyt")));
btnSettingsOk.setTooltip(
new Tooltip(bundle.getString("btnSettingsOkt")));
btnSettingsCancel.setTooltip(
new Tooltip(bundle.getString("btnSettingsCancelt")));
}
How can I hide tooltips? It seems to me that there isn't a straight-forward approach for this.
Any help is appreciated!
Upvotes: 10
Views: 5477
Reputation: 159321
For Controls
Controls have a setter for tooltips. So for controls, use that.
To set the tooltip on a control:
btnSettingsOk.setTooltip(new Tooltip("OK Button"));
To remove the tooltip on a control:
btnSettingsOk.setTooltip(null);
For Nodes which are not Controls
Layout panes, shapes and other nodes do not have a setter for tooltips (because tooltips are classified as controls and the JavaFX developers wanted to avoid a dependence of the general scene graph nodes on the controls package). However those nodes can still work with tooltips using the static install
and uninstall
methods.
This is pretty much Ikallas's answer, though I would only advise using it when the node type in question does not supply an explicit setTooltip
method - even though it will also work for controls. The set method on controls is simpler to use because the control stores a reference to the Tooltip, whereas, for an static uninstall, your application is responsible for keeping the reference to the tooltip so that it can later remove it.
To set the tooltip on a Node which is not a control:
Tooltip okTooltip = new Tooltip("OK Button");
Tooltip.install(btnSettingsOk, okTooltip)));
To remove the tooltip from a Node which is not a control:
Tooltip.uninstall(btnSettingsOk, okTooltip);
Upvotes: 15
Reputation: 1406
OK, just found answer to my own question :)
Tooltip.install(btnSettingsOk, new Tooltip(bundle.getString("btnSettingsOkt"))); //This is for showing
Tooltip.uninstall(btnSettingsOk, new Tooltip(bundle.getString("btnSettingsOkt"))); //This is for disabling
If there is some better way I would like to know about it ;)
Upvotes: 1