How can I add a clickable URL in a JTextArea?

2019-02-19 09:22发布

问题:

I am writing an application and in that I am using JTextArea to display some text. Now I want to show some clickable URL in text area along with the normal text and I want if user click on the URL then the web page that URL referring to should open in new web browser window.

回答1:

Use JEditorPane with HTMLEditorKit or JTextPane and set content type to "text/html"



回答2:

..url referring to should open in new web browser window.

// 1.6+
Desktop.getDesktop().browse(URI);