mal*_*ney 1 java swing jtextcomponent
我正在实施一个拼写检查器,并想知道是否有一种简单/明显的方法可以用不同的颜色(如Red)强调某些文本.
我已经设置了所有内容并使用以下代码加下划线(也设置了文本的颜色):
private AttributeSet getAttributeSet(Color foregroundColor) {
SimpleAttributeSet attrs = new SimpleAttributeSet();
StyleConstants.setForeground(attrs, foregroundColor);
StyleConstants.setUnderline(attrs, true);
}
Run Code Online (Sandbox Code Playgroud)
上面的代码将单词设置为蓝色,但也用蓝色加下划线.我需要能够改变下划线和厚度.有任何想法吗?
谢谢,
使用例如 http://java-sl.com/tip_colored_strikethrough.html
只需修改一下即可实现下划线而不是删除线.
但根据我的经验来突出拼写检查错误,最好定义自定义高亮画家
另见 http://www.java2s.com/Code/Java/Swing-JFC/JTextPaneHighlightExample.htm