appelstroopwafel
appelstroopwafel

Reputation: 3

Can I stylise just a part of a JavaFX Tooltip?

Just a simple snippet to add rows to a tooltip:

StringBuilder sb = new StringBuilder();
for (Object o : someList) {
  sb.append("\n").append(o.toString());
}
Tooltip t = new Tooltip(sb.toString());

But is it possible to make the style of the text row in my tooltip depend on the properties of the respective object? For example, if o.getReadyStatus() would be true, then I'd want the row to be boldened.

Upvotes: 0

Views: 28

Answers (1)

James_D
James_D

Reputation: 209319

You can't style different parts of the tooltip's text independently, but you can use the tooltip's graphic instead of the text to achieve what you want:

VBox vbox = new VBox();
for (Object o : someList) {
  Label label = new Label(o.toString());
  // style the label as needed...
  vbox.getChildren().add(label);
}
Tooltip t = new Tooltip();
t.setGraphic(vbox);

I haven't tested this: you may need some further styling on the VBox itself to get it to look good.

Upvotes: 1

Related Questions