你可能會考慮使用JXTable和JXHyperlink(無論是在SwingX project) - 他們支持超鏈接中渲染,完整的HyperlinkAction由桌面(由@Andrew湯普森提到的類)的支持
忘了提,適當的渲染器被默認爲類URI,一個代碼段,其通過點擊到含有URI的細胞觸發相應的桌面行動出關閉盒安裝:
// quick model which returns URI class
DefaultTableModel model = new DefaultTableModel(0, 1) {
@Override
public boolean isCellEditable(int row, int column) {
return false;
}
@Override
public Class<?> getColumnClass(int columnIndex) {
return URI.class;
}
};
// fill with supported uri types
model.addRow(new Object[]{new URI("mailto:[email protected]")});
model.addRow(new Object[] {new URI("http://swingx.java.net")});
model.addRow(new Object[] {new URI("http://stackoverflow.com/questions/9031371/how-to-show-url-as-a-click-able-url-in-jeditorpane-and-allow-them-to-open-in-def")});
model.addRow(new Object[] {new URI("http://dummy.org")});
// use in JXTable
JXTable table = new JXTable(model);
// that's it :-)
補遺
忽視了你的網址+文字的要求 - 在swingx默認支持,整個小區是可點擊,不僅URL的字符串表示
博爾更好地幫助越早請張貼http://sscce.org/demonstate您的問題 – mKorbel 2012-01-27 09:43:24
的可能重複[如何顯示URL,如表一點擊的網址,並允許他們在默認瀏覽器中打開?](http://stackoverflow.com/questions/9029514/how-to-show- url-as-a-click-able-url-in-table-and-allow-them-to-open-in-default-b) – trashgod 2012-01-27 12:20:30