JTextPane突出显示文本
我可以将一些文本突出显示到 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 highlight text ""
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
通常有几种可能性,具体取决于“突出显示”的真正含义:-)
通过更改文档级别上任意文本部分的任何样式属性来突出显示,例如
通过文本窗格级别上的荧光笔突出显示:
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
Highlight via a Highlighter on the textPane level:
https: //web.archive.org/web/20120530071821/http://www.exampledepot.com/egs/javax.swing.text/style_HiliteWords.html
https://web.archive.org/web/20120530071821/http://www.exampledepot.com/egs/javax.swing.text/style_HiliteWords.html
是的,您可以通过JTextPane继承自JTextComponent的函数setSelectionStart和setSelectionEnd。
看
JTextComponent.setSelectionStart 的 javadoc
Yes you can via the functions setSelectionStart and setSelectionEnd from JTextComponent which JTextPane inherits from.
see
javadoc of JTextComponent.setSelectionStart
您是否尝试过java的字符串比较方法
因为该方法允许搜索而无需考虑字符串的大小写
这可能是您想要实现的目标
希望这对您有帮助 Makky
Did you try java's string comparison method
Because this method allows a search without having to take the case of a string into account
This might be the ticket to what you are trying to achieve
Hope this helps you Makky
从性能角度来看,最好将 toUpperCase 放在
String text = doc.getText(0, doc.getLength()); 上
而不是在 while 循环中
,但感谢您提供了一个很好的例子。
performance wise its better to put the toUpperCase on
String text = doc.getText(0, doc.getLength());
rather than in the while loop
but thanks for the good example.