How to disable / hide tooltips in JavaFX

This is how I set the prompts:

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 to hide hints? It seems to me that there is no direct approach for this.

Any help is appreciated!

+6
source share
2 answers

For controls

The controls have a setter for tooltips . So for controls use this.

To set a tooltip in a control:

 btnSettingsOk.setTooltip(new Tooltip("OK Button")); 

To remove a tooltip on a control:

 btnSettingsOk.setTooltip(null); 

For nodes that are not controls

Panels, shapes, and other layout nodes do not have a tooltip set (since tooltips are classified as controls, and JavaFX developers need to avoid dependency of common scene graph nodes on the control pack). However, these nodes can work with tooltips using the static install and uninstall .

This is pretty much Ikallas answer, although I would recommend using it only when the node type does not provide an explicit setTooltip method, even if it will also work for controls. The set method on controls is easier to use because the control contains a link to a tooltip, while for static uninstallation, your application is responsible for maintaining a link to a tooltip so that it can later be deleted.

To set a tooltip on a node that is not a control:

 Tooltip okTooltip = new Tooltip("OK Button"); Tooltip.install(btnSettingsOk, okTooltip))); 

To remove a tooltip from a node that is not a control:

 Tooltip.uninstall(btnSettingsOk, okTooltip); 
+8
source

OK, I found the answer to my 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 a better way, I would like to know about it;)

+1
source

Source: https://habr.com/ru/post/984024/


All Articles