I'm using a TextFlow and some Text items to show a styled text, but i cant find a way to set a simple background color for the Text items.
I can set the fill color and font but it does not have a java method or css property that sets its background color.
Based on this solution, this is a quick implementation of a method to provide background coloring for all the
Textnodes within aFlowPane, using CSS and the ability to set a series of paint values separated by commas (as much asTextitems) and insets for each one of them:This will lead to this:
and after resizing the scene:
EDIT
Based on the OP request of using a
TextFlowlayout instead of aFlowPane, sinceTextnodes can be spanned over several lines within aTextFlow, the given solution will no longer be valid, as the bounding box of each text node will overlap others.As a workaround, we can split the
Textnodes in single wordTextnodes, while keeping the same background color for those in the same original phrase.I won't go into the splitting logic, but I will add a list of indices, where each index maps the text node with its index of background color.
This
FlowPanenow behaves as aTextFlow: