2016-06-29 10 views
0

Ich versuche, einen NotizPad-Bildschirm in meiner Anwendung zu erstellen. Nachdem die Notizen erstellt wurden, sind sie gesperrt und können nicht mehr bearbeitet werden. Es können jedoch neue Seiten zu einer Notiz hinzugefügt werden.Wie wird ein Seitenumbruch in einem TextFlow abgeleitet?

Ich dachte, dass die Verwendung des TextFlow wäre eine gute Kontrolle dafür. Was würde Ich mag tun, ist die folgende:

**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 

ich es auf diese Weise versucht haben:

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); 

Dieses mich sieht ziemlich viel, was ich will, mit Ausnahme der Separator nur eine winzige Linie ist. Ich möchte, dass die Linie den gesamten TextFlow durchquert und ich war mir nicht sicher, wie ich das anstellen soll.

Danke.

Antwort

2

Es gibt bereits eine JavaFX für Ihre Bedürfnisse in Steuer gebaut: ein 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(); 
} 

Separator

+0

Dank. Ich wusste nicht, dass ich es dimensionieren könnte. Werde es versuchen. –

0

fand ich eine Antwort, die funktioniert - obwohl ich nicht sicher bin, ob dies der beste Weg ist, es zu handhaben:

private void loadTextFlowWithNotes() { 
    textFlow.getChildren().clear(); 
    notes.forEach(note -> { 
     Text nameText = new Text("Taken By: " + note.takenBy); 
     nameText.setFill(Color.CRIMSON); 
     textFlow.getChildren().add(nameText); 
     textFlow.getChildren().add(new Text(System.lineSeparator())); 

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

     textFlow.getChildren().add(new Text(note.noteText)); 
     textFlow.getChildren().add(new Text(System.lineSeparator())); 
     textFlow.getChildren().add(new Text(System.lineSeparator())); 

     Line line = new Line(); 
     line.setStartX(0); 
     line.endXProperty().bind(textFlow.widthProperty()); 
     line.setFill(Color.CRIMSON); 
     textFlow.getChildren().add(line); 
     textFlow.getChildren().add(new Text(System.lineSeparator())); 
     textFlow.getChildren().add(new Text(System.lineSeparator())); 
    }); 
}