I'm using JavaFx for a little app and a want to display a tooltip on a textArea when the user is clicking on a "help" button.
No problem for linking a tootltip to my textArea, but no way to activate it when the user click on the button. Is there a way to do that?
This is what you are looking for:
final Button helpButton = new Button("Help");
helpButton.setOnAction(new EventHandler()
{
public void handle(Event arg0)
{
showTooltip(stage, helpButton, "test tool tip", null);
}
});
public static void showTooltip(Stage owner, Control control, String tooltipText,
ImageView tooltipGraphic)
{
Point2D p = control.localToScene(0.0, 0.0);
final Tooltip customTooltip = new Tooltip();
customTooltip.setText(tooltipText);
control.setTooltip(customTooltip);
customTooltip.setAutoHide(true);
customTooltip.show(owner, p.getX()
+ control.getScene().getX() + control.getScene().getWindow().getX(), p.getY()
+ control.getScene().getY() + control.getScene().getWindow().getY());
}
Just pass the button as an input instead of control.
The ability to display a Tooltip on demand requires a resolution of RT-19538 Customizable visibility timing for Tooltip, which is not implemented in JavaFX 2.2.
As a workaround, you could try any of the possible strategies below:
3rd party libraries such as Jide's JavaFX Beta Release provide special classes like Decorator utilities, IntelliHints and ShapedPopups which might be useful in your case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With