I have an ArrayList
that I am trying to get into a Tooltip
when the mouse hovers over a Node
. I have everything set, but I can't figure out how to wrap text in the Tooltip
in order to display each item in the ArrayList
on a separate line in the Tooltip
.
As a solution you can wrap the text within the width of the window by setting the value to the property wrapping with, using the setWrappingWidth() method. This method accepts a double value representing the width (in pixels) of the text.
You use the following approach to set a Tooltip on any node: Rectangle rect = new Rectangle(0, 0, 100, 100); Tooltip t = new Tooltip("A Square"); Tooltip. install(rect, t); This tooltip will then participate with the typical tooltip semantics (i.e. appearing on hover, etc).
String getToolTipText() Returns the string that was previously specified with setToolTipText .
Solution which does not rely on the deprecated TooltipBuilder:
Tooltip tooltip = new Tooltip(str);
tooltip.setPrefWidth(100);
tooltip.setWrapText(true);
You have to define 2 different properties, a prefWidth
for your tooltip and set wrapTextProperty
property to true
.
Your code will somewhat look like this
Tooltip t = TooltipBuilder.create().text(str).prefWidth(100).wrapText(true).build();
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