简体   繁体   English

有没有一种方法可以将Java文本区域中的每隔一行设置为不同的颜色?

[英]Is there a way to set every other line in a java text area to a different color?

I want to set every other line in a java text area to a second color, is there a way to do this? 我想将Java文本区域中的所有其他行设置为第二种颜色,有没有办法做到这一点?

example: 例:

<red>1</red>    
<blue>2</blue>
<red>3</red>    
<blue>4</blue>

the red and blue tags are just for example only. 红色和蓝色标签仅作为示例。

Neither java.awt.TextArea nor javax.swing.JTextArea support text (or background) decorations. java.awt.TextAreajavax.swing.JTextArea都不支持文本(或背景)修饰。 It is one font & one style. 它是一种字体和一种样式。

As indicated by Chris, a JTextPane (or JEditorPane ) is designed for 'styled text' documents. 如Chris所示, JTextPane (或JEditorPane )是为“样式化文本”文档设计的。 JEP for example, will handle RTF & (simple) HTML/CSS formatting. 例如,JEP将处理RTF和(简单)HTML / CSS格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM