gpt4 book ai didi

java - 使用 AttributeSet 在不同颜色下划线 StyleConstant

转载 作者:行者123 更新时间:2023-11-29 08:08:44 39 4
gpt4 key购买 nike

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

我已设置好所有内容并使用以下代码加下划线(还设置了文本的颜色):

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

上面的代码将单词设置为蓝色,但也用蓝色下划线。我需要能够更改下划线及其粗细。有什么想法吗?

谢谢,

最佳答案

使用例如这个 http://java-sl.com/tip_colored_strikethrough.html

只需修改一下即可实现下划线而不是删除线。

但根据我的经验,要突出显示拼写检查错误,最好定义自定义突出显示画家

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

关于java - 使用 AttributeSet 在不同颜色下划线 StyleConstant,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9502654/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com