JavaFX - How to apply different colors for words in Label


I am new to JavaFX. I want to make the text of Label with different colors.

For Example:

Label : "sourav ganguly"

Ouput: sourav(as red color) ganguly(as blue color)

I tried but i didn't get it. Please can anyone help me.

7/29/2013 6:32:59 AM

Accepted Answer

Create a custom cellfactory for your ListView and have it generate cells containing a FlowPane with different Text instances, each with different styles. I created a sample to demonstrate this method.

Sample output:

colorized text

In Java 8 you can you can use the TextFlow to style your text rather than a combination of different Text instances in a FlowPane.

7/30/2014 8:59:27 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow