Jlabel HTML 格式 [英] Jlabel HTML formatting
问题描述
我有一个 JLabel,里面有一个电子邮件地址.我在 JLabel 上使用了 HTML 格式,因此它显示为链接.但是,您无法单击该链接.实际上,您无法选择标签中的任何文本.是否有我可以在 JLabel 上设置的属性,以允许用户至少选择电子邮件的文本,并且最好像他们在网页上一样单击电子邮件地址?
I have a JLabel which has an e-mail address in it. I used HTML formatting on the JLabel, so it appears as a link. 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 l = new JLabel("<html><a href=\"mailto:bob@bob.com\">bob@bob.com</a>");
推荐答案
默认的 JLabel
不允许您这样做.如果您真的想使用 JLabel
,您可以向其添加一个鼠标侦听器来捕获点击并对其做出反应.另一种方法是使用不可编辑的 JEditorPane
并在其上调用 addHyperlinkListener
以添加您的 HyperlinkListener
.
The default JLabel
doesn't allow you to do this. If you really want to use a JLabel
, you could add a mouse listener to it to capture clicks and react to them. Another way would be to use a non-editable JEditorPane
and call addHyperlinkListener
on it to add your HyperlinkListener
.
这篇关于Jlabel HTML 格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!