apizzimenti
apizzimenti

Reputation: 467

Highlighting specific instances of a string for output to TextArea

I have a search function that scrolls through a String and finds specific instances of a substring and then notes the index for the location of the substring.

For example, if I'm trying to find the String

"AATACG"

in the string

"TACGATCAATACGACGATCAGT",

it will return 7 as the index of the substring. What I need is a way to color the substring. So, the return text will be

"TACGATCAATACGACGATCAGT",

but with the substring colored. The text is outputted to a JavaFX TextArea.

I've tried using ANSI codes (which didn't work); I've also tried changing the string into a Text object and setting the fill color/applying a CSS id, but I can't find a way to change the Text back into a String with the color change remaining.

Is there a way to do this? Any help is much appreciated.

Upvotes: 0

Views: 408

Answers (1)

Maxim
Maxim

Reputation: 9961

How about using javafx.scene.text.TextFlow? Seems like you want to highlight text without editing it. In this case TextFlow is appropriate component.

Upvotes: 3

Related Questions