TextFlow in JavaFX does not show anything


Question

I have created a UI for my application using "JavaFX Scene Builder".

I need to show text inside the TextFlow object so in my class (implements javafx.fxml.Initializable ) I write this

public void initialize(URL location, ResourceBundle resources)
{    
     Text t1 = new Text("My name is Josh!");
     tofl = new TextFlow(t1);
}

This way my TextFlow object does not show the Text at all. Should I call a method on tofl like tofl.apply()to let the text appear?

TextFlow is initialized as a fieldabove the method, it is all linked with fxlm file too. Using TextArea everything works fine instead.

1
1
10/7/2014 8:05:41 AM

Accepted Answer

You are re-initializing your TextFlow to a new TextFlow object. You should never do that with fields linked with @FXML

If you want to add Text to the textFlow(defined in your FXML), use :

public void initialize(URL location, ResourceBundle resources)
{    
     Text t1 = new Text("My name is Josh!");
     tofl.getChildren().add(t1);
}
4
10/7/2014 8:29:49 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon