如何在URL中显示URL作为可点击的URL并允许它们在默认浏览器中打开? [英] How to show URL as a click-able URL in Table and allow them to open in default browser?
问题描述
我有一个Java Desktop应用程序,它在 JTable
中显示一些信息,这些信息可能包含某些单元格中包含某些文本的URL。如何才能使URL可点击并允许用户在默认浏览器中打开它,如果他/她点击它。 > here 在自定义 TableCellEditor的
。一旦选定,您可以 browse()
URI。
附录:您可以使用 I have Java Desktop application that displays some information in a You can use the approach shown here in a custom Addendum: You can use
这篇关于如何在URL中显示URL作为可点击的URL并允许它们在默认浏览器中打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! 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){
//打开浏览器
}
}
});
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. TableCellEditor
. Once selected, you can browse()
the URI.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
}
}
});