Underline StyleConstant in a different colour with AttributeSet

≡放荡痞女 提交于 2020-01-15 15:29:54

问题


I am implementing a spellchecker and wondered if there is an easy/obvious way of underlining some text in a different colour such as Red.

I have everything set up and underlining with the following code (also sets the color of the text):

private AttributeSet getAttributeSet(Color foregroundColor) {
    SimpleAttributeSet attrs = new SimpleAttributeSet();
    StyleConstants.setForeground(attrs, foregroundColor);
    StyleConstants.setUnderline(attrs, true);
}

The above code sets the word to blue but also underlines it in blue. I need to be able to change the underline and also its thickness. Any ideas?

Thanks,


回答1:


Use e.g this http://java-sl.com/tip_colored_strikethrough.html

Just modify it a bit to achieve underline rather than strikethrough.

But from my experience to highlight spellcheck errors it's better to define custom highlight painter

See also http://www.java2s.com/Code/Java/Swing-JFC/JTextPaneHighlightExample.htm



来源:https://stackoverflow.com/questions/9502654/underline-styleconstant-in-a-different-colour-with-attributeset

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