正如我在评论中建议的那样你应该尝试使用JTextPane而不是JTextArea.
为了使超链接工作,您需要做以下事情:
快速演示如下:
final JTextPane textPane = new JTextPane();
textPane.setEditable(false);
textPane.setContentType("text/html");
textPane.setText("File not found please contact:<a href='mailto:michael@uml.com'>e-mail to</a> or call 9639");
textPane.addHyperlinkListener(new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
if(e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
System.out.println(e.getURL());
// write your logic here to process mailTo link.
}
}
});
Run Code Online (Sandbox Code Playgroud)
通过java打开邮件客户端的示例:
try {
Desktop.getDesktop().mail(new URI(e.getURL() + ""));
} catch (IOException e1) {
e1.printStackTrace();
} catch (URISyntaxException e1) {
e1.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2443 次 |
| 最近记录: |