2012-05-25 89 views
0

我想了解如何创建一个包含图像的JTable单元格,该图像应该可以像超级链接一样点击。我可以使用默认图像渲染器加载图像。如何创建包含图像超链接的JTable单元格?

My table with expected image hyperlinks in the last column

有人能解释我如何在我的表的最后一栏增加为每幅图像(小区)的超链接(鼠标监听)?这样,当jTable单元格中的图像链接被点击时,我希望它打开弹出窗口,并显示一条显示错误消息的消息。

感谢, 钱德拉

回答

3

要在机器的默认浏览器中启动链接:

URI uri = null; 
try { 
    uri = new URI(urlToOpen); 
} catch (URISyntaxException e1) { 
    System.out.println("Malformed URI: " + uri); 
} 
Desktop desktop = Desktop.getDesktop(); 
try { 
    desktop.browse(uri); 
} catch (IOException e2) { 
    // If the user default browser is not found, or it fails 
    // to be launched, or the default handler application 
    // failed to be launched 
    JOptionPane.showMessageDialog(null, 
     "The application could not find any compatible browser."); 
} 

您可以在图片的点击做到这一点。


编辑基于评论:

添加监听到的图像,然后你可以一个JOptionPaneJDialog对图像点击打开。

+0

感谢您的回答。我已更新我的问题,以更具体地了解我的要求。我不确定这可以根据我的情况进行定制。你的评论? – merlachandra

+0

@merlachandra所以你想要点击图像打开弹出? –

+0

是的。而图像是Jtable Cell的内容。 – merlachandra

相关问题