如何推断 TextFlow 中的分页符?

pur*_*eon 1 textflow javafx-8

我正在尝试在我的应用程序中创建一个记事本屏幕。创建注释后,它们将被锁定且无法编辑,但是可以将新页面添加到注释中。

我认为使用 TextFlow 可以很好地控制这一点。我想做的是:

**Note Taker Name**
**Date of Note**
Line of Note Text
Line of Note Text
Line of Note Text
Line of Note Text
------------------------------------------
**Note Taker Name**
**Date of Note**
Line of Note Text
Line of Note Text
Line of Note Text
Line of Note Text
Run Code Online (Sandbox Code Playgroud)

我已经尝试过这种方式:

String s1 = "line of text";

textFlow.getChildren().add(new Text(s1));
textFlow.getChildren().add(new Text(System.lineSeparator()));
textFlow.getChildren().add(new Separator(Orientation.HORIZONTAL));
textFlow.getChildren().add(new Text(System.lineSeparator()));
textFlow.getChildren().add(new Text(s1));

scrollPane.setFitToWidth(true);
Run Code Online (Sandbox Code Playgroud)

这几乎为我提供了我想要的东西,除了分隔符只是一条细线。我希望该线穿过整个 TextFlow,但我不太确定如何去做。

谢谢。

Jos*_*eda 5

已经有一个 JavaFX 内置控件可以满足您的需求:a Separator( javadoc )。

@Override
public void start(Stage primaryStage) {
    TextFlow textFlow = new TextFlow();
    Text nameText = new Text("Taken By me ");
    nameText.setFill(Color.CRIMSON);
    textFlow.getChildren().add(nameText);
    textFlow.getChildren().add(new Text(System.lineSeparator()));

    Text takenOn = new Text("Taken On: " + DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT).format(LocalDateTime.now()));
    takenOn.setFill(Color.CRIMSON);
    textFlow.getChildren().add(takenOn);
    textFlow.getChildren().add(new Text(System.lineSeparator()));

    textFlow.getChildren().add(new Text("this is a note"));
    textFlow.getChildren().add(new Text(System.lineSeparator()));

    // Separator
    final Separator separator = new Separator(Orientation.HORIZONTAL);
    separator.prefWidthProperty().bind(textFlow.widthProperty());
    separator.setStyle("-fx-background-color: red;");
    textFlow.getChildren().add(separator);

    textFlow.getChildren().add(new Text(System.lineSeparator()));
    textFlow.getChildren().add(new Text("this is another note"));

    Scene scene = new Scene(textFlow, 300, 250);

    primaryStage.setTitle("Hello World!");
    primaryStage.setScene(scene);
    primaryStage.show();
}
Run Code Online (Sandbox Code Playgroud)

分隔器