2016-06-29 4 views
0

私のアプリケーションでノートパッドの画面を作成しようとしています。ノートが作成されると、それらはロックされ、編集することはできませんが、ノートに新しいページを追加することができます。TextFlowでページ区切りを推測するには?

私は、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 

私はそれをこのようにしようとしています

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

これは、セパレータを除いて、私が欲しいものはかなり私を提供ほんのラインです。私は、そのラインがTextFlow全体を横切ることを望んでおり、私はそれについてどうやって行くのか本当に分かりませんでした。

ありがとうございました。

答えて

2

JavaFXのは、あなたのニーズに合わせてコントロールに建てすでにあり:Separatorjavadoc) 。

@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

感謝。私はそれを大きさにすることができないことを理解していなかったそれを撃つだろう。 –

0

私は作品の答えを見つけた - 私はこれはそれを処理するための最良の方法であるかどうかわからないですけれども:

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