java 如何在 jtextarea 中获取突出显示的文本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6360017/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 15:33:29  来源:igfitidea点击:

How to get highlighted text in a jtextarea

javaswingjtextareaswing-highlighter

提问by Nuwan

I have a jtextarea with some texts. I use java highligher to highlight some texts on that jtextarea. I want to print the content of that textarea to another textarea with the highlighted texts. Is that possible? Or is there any way of getting only the highlighted text inside a jtextarea?

我有一个带有一些文本的 jtextarea。我使用 java highligher 来突出显示该 jtextarea 上的一些文本。我想将该文本区域的内容打印到另一个带有突出显示文本的文本区域。那可能吗?或者有没有办法只获取 jtextarea 中突出显示的文本?

回答by Atreys

Use the getHighlights()method of your Highlighter. From there, you can retrieve the offsets of the start and end of highlighting.

使用荧光笔的 getHighlights()方法。从那里,您可以检索突出显示开始和结束的偏移量。

回答by Waldheinz

You can just ask the text area for the selected text using the getSelectedTextmethod.

您可以使用该getSelectedText方法向文本区域询问所选文本。