JTextPane突出显示文本 [英] JTextPane highlight text
本文介绍了JTextPane突出显示文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以将一些文字突出显示在 JTextPane
中,从一个值开始,从另一个值
结束,如下所示,但是颜色为黄色?
Can I highlight some text into a JTextPane
starting from a value and ending from another value
like the following but with the yellow color?
JTextPane 突出显示文字
谢谢。
推荐答案
通常有几种可能性,取决于你的亮点的真正含义: - )
As often there are several possibilities, depending on what you really mean by "highlight":-)
通过更改文档级别上任意文本部分的任何样式属性来突出显示,例如
Highlight by changing any style attributes of arbitrary text parts on the document level, something like
SimpleAttributeSet sas = new SimpleAttributeSet();
StyleConstants.setForeground(sas, Color.YELLOW);
doc.setCharacterAttributes(start, length, sas, false);
在textPane级别通过荧光笔突出显示:
Highlight via a Highlighter on the textPane level:
DefaultHighlighter.DefaultHighlightPainter highlightPainter =
new DefaultHighlighter.DefaultHighlightPainter(Color.YELLOW);
textPane.getHighlighter().addHighlight(startPos, endPos,
highlightPainter);
这篇关于JTextPane突出显示文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文