简体   繁体   English

Jlabel HTML格式

[英]Jlabel HTML formatting

I have a JLabel which has an e-mail address in it. 我有一个带有电子邮件地址的JLabel。 I used HTML formatting on the JLabel, so it appears as a link. 我在JLabel上使用了HTML格式,因此它显示为链接。 However, you are not able to click the link. 但是,您无法单击该链接。 In fact, you cannot select any of the text in the label. 实际上,您不能选择标签中的任何文本。 Is there a property that I can set on the JLabel to allow the user to at least select the text of the e-mail, and preferably to click on the e-mail address the way they would on a webpage? 我可以在JLabel上设置一个属性,以允许用户至少选择电子邮件的文本,并且最好像在网页上那样单击电子邮件地址吗?

My code for my JLabel is essentially: 我的JLabel代码基本上是:

JLabel l = new JLabel("<html><a href=\"mailto:bob@bob.com\">bob@bob.com</a>");

The default JLabel doesn't allow you to do this. 默认的JLabel不允许您执行此操作。 If you really want to use a JLabel , you could add a mouse listener to it to capture clicks and react to them. 如果您确实想使用JLabel ,则可以向其添加鼠标侦听器以捕获单击并对其做出反应。 Another way would be to use a non-editable JEditorPane and call addHyperlinkListener on it to add your HyperlinkListener . 另一种方法是使用不可编辑的JEditorPane并对其调用addHyperlinkListener来添加HyperlinkListener

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

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