如何获得JEditorPane突出显示一行的整个宽度(而不仅仅是文本)? [英] How do I get a JEditorPane to highlight the full width of a line (not just the text)?
问题描述
我正在尝试获取JEditorPane以突出显示显示行的整个宽度.我尝试过的所有示例都只突出文本内容.例如,如果我有这样的内容:
I'm trying to get a JEditorPane to highlight the full width of a displayed line. All the examples I've tried only highlight the textual content. For example if I have content such as this:
---------------------------------
|Here is some text |
|some more text |
---------------------------------
在上方方框表示的JEditorPane中,然后突出显示第一行,仅突出显示此处是某些文本"(表示在下面的[和]之间).
within a JEditorPane represented by the box above, then highlighting the first row highlights only the 'Here is some text' (represented between [ and ] below).
---------------------------------
[Here is some text] |
|some more text |
---------------------------------
我希望突出显示JEditorPane的整个宽度,如下所示:
I would like it to highlight the full width of the JEditorPane like the following:
---------------------------------
[Here is some text ]
|some more text |
---------------------------------
有没有办法做到这一点?
Is there a way to do this?
推荐答案
这似乎不太复杂.我会说一下 代码挑战 .
This seems not too complicated. I would make that a little code-challenge.
只需创建自己的自定义荧光笔,即可扩展DefaultHighlighter.
Just create your own custom Highlighter, extending DefaultHighlighter.
重写paint()
方法,仅保留矩形绘画的宽度不变:它将是面板的宽度.
Override the paint()
method, and simply leave unchanged the width of the rectangle paint: it will be the width of the panel.
您将在 DZone代码段中找到完整的示例 :复制并运行它.告诉我这是否是你要的.它包括您在答案中提到的textPane.setSelectionColor(new Color(1.0f, 1.0f, 1.0f, 0.0f));
附加内容.
替代文字http://www.freeimagehosting.net/uploads/94a3a990e4.png
这篇关于如何获得JEditorPane突出显示一行的整个宽度(而不仅仅是文本)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!