How to make a JTable cell (link) clickable

java, jtable, sql-server, swing

Solution

Consider using JXTable (a class of SwingX): it supports a hyperlink renderer which can be configured to do any action, based on the cell value

JXTable table = new JXTable(myModel);
AbstractHyperlinkAction<Object> simpleAction = new AbstractHyperlinkAction<Object>(null) {

    public void actionPerformed(ActionEvent e) {
        // here goes what you want to do on activating the hyperlink
        //LOG.info("hit: " + getTarget());
    }

};
TableCellRenderer renderer = new DefaultTableRenderer(
    new HyperlinkProvider(simpleAction));
table.getColumnExt(0).setEditable(false);
table.getColumnExt(0).setCellRenderer(renderer);

Problem

I am making a hospital project in Java, I have made a `JTable` which is fetching Hospital Name and a Hospital image link i.e `"Click to see more"` from SQL database. My problem is that the data is successfully fetched from database to the table, but I can't click the link which is in the table cell. How to make the link active?

Original source

Related problems