JavaFX TextFlow without linebreaks

1.8k Views Asked by At

Is there a way to prevent a JavaFX TextFlow control or its Text children nodes to break lines. I want a TextFlow without line break growing horizontally.

TextFlow textFlow = new TextFlow();
Text text = new Text("A verrrrryyyyy llllooooonnnnggggg Text that shouldn't contain line breaks.");
textFlow.getChildren().add(text);

Setting setWrappingWidth to a very high value didn't remove line breaks for me. Any help is appreciated.

2

There are 2 best solutions below

1
On BEST ANSWER

To quote the API doc of TextFlow:

The wrapping width of the layout is determined by the region's current width. It can be specified by the application by setting the textflow's preferred width. If no wrapping is desired, the application can either set the preferred with to Double.MAX_VALUE or Region.USE_COMPUTED_SIZE.

I tried this briefly and depending on the Parent container it seems to work as you intended it.

0
On

Come across similar problem and just want to share my solution. You can use non-breaking space "\u00A0" like:

TextFlow textFlow = new TextFlow();
Text text = new Text("A\u00A0verrrrryyyyy\u00A0llllooooonnnnggggg\u00A0Text\u00A0that shouldn't\u00A0contain\u00A0line\u00A0breaks.");
textFlow.getChildren().add(text);