【发布时间】:2021-03-02 03:22:16
【问题描述】:
请有人告诉我如何禁用JTextPane 的文本突出显示。
我的JTextPane 是半透明的,因此突出显示的错误。但是没有突出显示是好的!
我尝试了以下方法:
DefaultHighlighter highlighter = (DefaultHighlighter) chatTextPane.getHighlighter();
highlighter.removeAllHighlights();
chatTextPane.setHighlighter(null);
chatTextPane.setSelectedTextColor(new Color(0,0,0,0));
chatTextPane.setSelectionColor(new Color(0,0,0,0));
chatTextPane.setSelectionStart(0);
chatTextPane.setSelectionEnd(0);
chatTextPane.setCaret(new NoTextSelectionCaret(chatTextPane));
// with:
private class NoTextSelectionCaret extends DefaultCaret
{
public NoTextSelectionCaret(JTextComponent textComponent)
{
setBlinkRate( textComponent.getCaret().getBlinkRate() );
textComponent.setHighlighter( null );
}
@Override
public int getMark()
{
return getDot();
}
}
还有一些关于highlighter.getDrawsLayeredHighlights(); 的东西我什至不记得了。
谢谢!
【问题讨论】:
-
您的意思是您不想让用户使用鼠标或键盘选择
JTextPane中的文本?换句话说,如果用户将鼠标拖过JTextPane中的某些文本,那么该文本不会被突出显示? -
为什么不让突出显示与 jtextpane 背景颜色相同,这样您根本看不到它?
-
我的 JTextPane 是半透明的 - 请参阅 Backgrounds With Transparency 了解可能的问题和一些解决方案。
-
@camickr 谢谢!我能弄明白
-
@Abra 这就是我的意思。我的问题是突出显示文本时出现的不良伪影
标签: java swing user-interface highlight jtextpane