I'm trying to use the LinkRenderer on a JXTable with no success. I see in the examples that the "right" way to do this is to have a LinkModel.class returned for the column from the TableModel. However, I'm not able to modify the TableModel in this case (technically I could, but any solution that requires that much work is the wrong solution, IMO).
I want to do something like this:
<br /> JXTable table = new JXTable();<br /> //The model has two columns, customer_name<br /> //(a String) and order_num (an Integer).<br /> //I want both to have hyperlinks, and when they<br /> //are clicked I want a different action listener<br /> //invoked that will open the proper dialog or<br /> //whatever<br /> table.setModel(...);<br /> TableColumn col = table.getColumnExt("customer_name");<br /> col.setCellRenderer(new LinkRenderer(<br /> new OpenCustomerListener()));<br /> col = table.getColumnExt("order_num");<br /> col.setCellRenderer(new LinkRenderer(<br /> new OpenOrderListener()));<br />
This code doesn't appear to work. I tried to track down the cause, but the code was... hard to follow. LinkAction, JXHyperlink, LinkModel, BasicHyperlinkUI are all involved. The Hyperlinks doen't draw their underline (either always, or when hovered over). Initially the text didn't even show in the table -- I had to modifiy this line in LinkRenderer (in getTableCellRendererComponent):
<br /> linkAction.setLink(value instanceof LinkModel ? (LinkModel) value : new LinkModel(value == null ? "" : value.toString()));<br />
(added in the auto LinkModel creation).