0

I'm having a TextFlow inside a StackPane which is inside a ScrollPane. I'm adding text with different colors to this TextFlow

Text txt = new Text(msg);
txt.setFill(Paint.valueOf(color));
txtFlow.getChildren().add(txt);

I want to scroll to a some specific point in the textflow.

e.g. First text that is in blue color.

I know I can get the text and check the color. But how can I scroll down to that specific position?

Can I achieve that sort of functionality through the TextFlow? Simply I'm trying to build up a diff view in JavaFX. And want to travel through the diffs.

2 Answers2

1

I would take a ListView and put some stackpanes or directly the texts in it.

Text content = new Text("Custom Text");
content.setFill(Color.valueOf(yourcolor));   
ListView<Text> list = new ListView<Text>();
list.add(content);

Because... there's a void scrollTo() where you can scroll to the item directly by the Text object or to the item by the index (int).

To get a transparent background on the listview you can use:

list.setStyle("-fx-background-color: transparent;");

I hope this helped you. I'm sorry if I missunderstood your question.

Peace

siegy22
  • 4,295
  • 3
  • 25
  • 43
1

Use one of the free styledtext-editors - they all are using ListView or VirtualView internally. See https://github.com/TomasMikula/RichTextFX/wiki/JavaFX-Controls-for-Code-Editing for examples

tomsontom
  • 5,856
  • 2
  • 23
  • 21