0

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.

alex
  • 5,516
  • 2
  • 36
  • 60

2 Answers2

2

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.

eckig
  • 10,964
  • 4
  • 38
  • 52
  • Ok, then my problem lies elsewhere because the use of Region.USE_COMPUTED_SIZE was correct. Thanks! – alex Nov 13 '14 at 10:15
0

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);
PH88
  • 1,796
  • 12
  • 12