0

How can I reduce the space between the 2 texts?

I have the following code:

Text t1 = new Text("Header Text");
Text t2 = new Text("\nBody Text");
TextFlow textFlow = new TextFlow(t1,t2);
textFlow.setTextAlignment(TextAlignment.CENTER);
textFlow.setPadding(new Insets(0));

The gap between "Header Text" and "Body Text" is too wide, is there any way i can reduce this space? I'm using JavaFX Text.

Miss Chanandler Bong
  • 4,081
  • 10
  • 26
  • 36
Cherple
  • 725
  • 3
  • 10
  • 24
  • 1
    Please post [mre] showing the problem. – c0der Dec 30 '19 at 04:54
  • I'm not sure what you mean? That is all there is. The textflow can be placed in any pane and the results will be the same. It will display 2 lines of text with header on top and body at the bottom. – Cherple Dec 30 '19 at 08:43
  • Does setting [bounds type](https://openjfx.io/javadoc/13/javafx.graphics/javafx/scene/text/Text.html#boundsTypeProperty) or [line spacing](https://openjfx.io/javadoc/13/javafx.graphics/javafx/scene/text/Text.html#lineSpacingProperty) on the Text or the [line spacing](https://openjfx.io/javadoc/13/javafx.graphics/javafx/scene/text/TextFlow.html#lineSpacingProperty) on the TextFlow help or fix your issue? If not, can you edit the question to include two pictures? One picture of what the output currently looks like and another one of what you want it to look like. – jewelsea Dec 30 '19 at 08:58

1 Answers1

1

You can set line spacing for a TextFlow. The default value is already 0, so you can make them look closer to each other by giving a negative value:

textFlow.setLineSpacing(-2.0);
Miss Chanandler Bong
  • 4,081
  • 10
  • 26
  • 36