简体   繁体   English

在jTextArea中显示超链接

[英]Display hyperlinks in a jTextArea

I did a search engine where I can enter some words and find the links where this words appears. 我做了一个搜索引擎,可以在其中输入一些单词并找到出现这些单词的链接。 But when I display this links, I am displaying it as string, and I want to display it as hyperlinks, that the user can click and connect to the site. 但是,当我显示此链接时,我将其显示为字符串,并且希望将其显示为超链接,以便用户可以单击并连接到该站点。 I used the solutions I found here on stackoverflow, but none of then worked. 我使用了在stackoverflow上找到的解决方案,但是没有一个起作用。

Does anyone knows how can I do it? 有谁知道我该怎么办? At the moment, I am displaying the results inside a jTextArea. 目前,我正在jTextArea中显示结果。

I am displaying the results inside a jTextArea 我在jTextArea中显示结果

You can't use a JTextArea. 您不能使用JTextArea。 A JTextArea only displays simple text. JTextArea仅显示简单文本。

You need to display HTML in a JEditorPane and add the links using HTML. 您需要在JEditorPane显示HTML,并使用HTML添加链接。 Then you add a HyperLinkListener to the editor pane. 然后,将HyperLinkListener添加到编辑器窗格。

Read the section from the Swing tutorial on How to Use Editor Panes for general information and examples. 阅读Swing教程中有关如何使用编辑器窗格的部分, 获取常规信息和示例。

Read the JEditorPane API for an example on how to create a HyperLinkListener and respond to mouse clicks. 阅读JEditorPane API,获取有关如何创建HyperLinkListener和响应鼠标单击的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM