使用 AttributeSet 以不同颜色下划线 StyleConstant [英] Underline StyleConstant in a different colour with AttributeSet

查看:36
本文介绍了使用 AttributeSet 以不同颜色下划线 StyleConstant的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实施拼写检查器,想知道是否有一种简单/明显的方法可以用不同的颜色(例如红色)为某些文本加下划线.

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?

谢谢,

推荐答案

使用例如这个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

另见http://www.java2s.com/Code/Java/Swing-JFC/JTextPaneHighlightExample.htm

这篇关于使用 AttributeSet 以不同颜色下划线 StyleConstant的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆