如何在URL中显示URL作为可点击的URL并允许它们在默认浏览器中打开? [英] How to show URL as a click-able URL in Table and allow them to open in default browser?

查看:109
本文介绍了如何在URL中显示URL作为可点击的URL并允许它们在默认浏览器中打开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java Desktop应用程序,它在 JTable 中显示一些信息,这些信息可能包含某些单元格中包含某些文本的URL。如何才能使URL可点击并允许用户在默认浏览器中打开它,如果他/她点击它。 > here 在自定义 TableCellEditor的 。一旦选定,您可以 browse() URI。



附录:您可以使用 JEditorPane 为您的编辑器组件和

<$> p $ p> JEditorPane jep = new JEditorPane();
jep.addHyperlinkListener(new HyperlinkListener(){
$ b $ @Override
public void hyperlinkUpdate(HyperlinkEvent e){
HyperlinkEvent.EventType type = e.getEventType();
final URL url = e.getURL();
if(type == HyperlinkEvent.EventType.ENTERED){
//希望高亮显示
} else if(type == HyperlinkEvent.EventType.ACTIVATED){
//打开浏览器
}
}
});


I have Java Desktop application that displays some information in a JTable that may contain URLs with some text in some cells. How can I make only the URL click-able and allow the user to open it in a default browser if he/she clicks on it.

You can use the approach shown here in a custom TableCellEditor. Once selected, you can browse() the URI.

Addendum: You can use JEditorPane for your editor component and addHyperlinkListener() to listen for events related to the link.

JEditorPane jep = new JEditorPane();
jep.addHyperlinkListener(new HyperlinkListener() {

    @Override
    public void hyperlinkUpdate(HyperlinkEvent e) {
        HyperlinkEvent.EventType type = e.getEventType();
        final URL url = e.getURL();
        if (type == HyperlinkEvent.EventType.ENTERED) {
            // do desired highlighting
        } else if (type == HyperlinkEvent.EventType.ACTIVATED) {
            // open browser
        }
    }
});

这篇关于如何在URL中显示URL作为可点击的URL并允许它们在默认浏览器中打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆