gpt4 book ai didi

java - 将外部 URL 添加到 JLabel

转载 作者:行者123 更新时间:2023-12-04 06:16:14 24 4
gpt4 key购买 nike

我需要为 JLabel 中的特定单词添加一个 URL。

例如 :
JLabel 是“请单击此处报告问题”

现在我的要求只是“点击”应该作为链接工作,而不是完整的 JLabel。
我尝试了一种解决方法,即整个 JLabel 被转换为链接。

    String labeltext = "<html><font color='black'>This is where you can log your time activity for the presales process. We are constantly " +
"upgrading our presales tools, <br /> so if you have any feedback, please click <a href='#' style='color: blue;'>here</a> to send us the request.</font></html>";
JLabel lbl = new JLabel(labeltext);

lbl.addMouseListener(new MouseListener() {

@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub

}

@Override
public void mousePressed(MouseEvent e) {
Desktop desktop = Desktop.getDesktop();
try {
URI uri = new URI("10.5.44.108/issue.html");
desktop.browse(uri);
} catch (Exception ex) {
}
}

@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub

}

@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub

}

@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub

}
});

如果有人对实现这一目标有任何建议,请告诉我。

提前致谢 !!

此致,
高拉夫

最佳答案

如果您想将 html 组件嵌入到您的 Java 应用程序中,请查看 JEditorPane .
这是一个 tutorial .

关于java - 将外部 URL 添加到 JLabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7203710/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com