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

ⅰ亾dé卋堺 提交于 2020-01-21 23:54:17

问题


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?


回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/30114478/is-it-possible-to-set-different-colors-for-different-lines-in-a-javafx-textfield

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!