Crossposted:
• https://community.oracle.com/message/13853226#13853226
• http://www.coderanch.com/t/666101/JavaFX/java/TextFlow-FXML#3105251
I am trying to use TextFlow coming from FXML in controller during app execution (not at start-up) but no text is shown.
I have tried:
textflow.getChildren.add(text);
and also:
textflow=new TextFlow(text);
where text is:
Text text=new Text("AAA");
I both cases TextFlow shows nothing.
Is there another container for use with rich text using FXML JavaFX app?
For sure if I try both cases in non-FXML JavaFX app it works both of them.
Update:
TextFlow in FXML looks like this
<TextFlow fx:id="txtFlow" layoutX="20.0" layoutY="230.0" prefHeight="70.0" prefWidth="430.0" style="-fx-border-color: ADD9E6;" AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="140.0">
FXML
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.TextFlow?>
<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml/1" fx:controller="testfxmlpackage.FXMLDocumentController">
<children>
<TextFlow fx:id="txtF" layoutX="22.0" layoutY="234.0" prefHeight="74.0" prefWidth="433.0" style="-fx-border-color: ADD8E6;" AnchorPane.bottomAnchor="14.0" AnchorPane.leftAnchor="22.0" AnchorPane.rightAnchor="142.0" />
</children>
</AnchorPane>
Controller
package testfxmlpackage;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.text.Text;
import javafx.scene.text.TextFlow;
public class FXMLDocumentController implements Initializable {
@FXML TextFlow txtF;
@Override
public void initialize(URL url, ResourceBundle rb) {
txtF=new TextFlow(new Text("aaa"));
txtF.getChildren().add(new Text("aaa"));
}
}
Main Class
package testfxmlpackage;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class TestFXMLPackage extends Application {
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}