Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to set different colors for different lines in a javafx textField/Area?

I know that you can set a color of a whole textArea/Field by setting the style of the node to be -fx-text-fill: red; but is there a way to set the color of one single line instead of all of the lines while still keeping the textArea/Field editable?

like image 361
sazzy4o Avatar asked Dec 05 '22 03:12

sazzy4o


2 Answers

With javaFX 8 (released March, 2016) it is possible to use TextFlow instead of TextArea or TextField. It allows different colors, fonts etc.

https://docs.oracle.com/javase/8/javafx/user-interface-tutorial/text-settings.htm

https://docs.oracle.com/javase/8/javafx/api/javafx/scene/text/TextFlow.html

like image 152
Vittori0 Avatar answered Dec 06 '22 18:12

Vittori0


JavaFX's TextField/TextArea does not support that. You can use RichTextFX for the job:

import org.fxmisc.richtext.InlineCssTextArea;

InlineCssTextArea area = new InlineCssTextArea();

// set style of line 4
area.setStyle(4, "-fx-fill: red;");
like image 29
Tomas Mikula Avatar answered Dec 06 '22 18:12

Tomas Mikula