0

I want to add an actionListener to JTable cell value which means when the user clicks on cell text, an action going to call. The text of the cell value will show like a hyperlink. which allows the user to click on it.

  • Important note: I know how to add an action to the whole cell. My problem is that I want to add it to just a text like a link.
Emad
  • 769
  • 9
  • 21
  • For clickable links in your cells you can use a JEditorPane for the cell content, and use a HyperLinkListener as explained [in this thread](http://stackoverflow.com/questions/3693543/hyperlink-in-jeditorpane) – Lolo Apr 27 '14 at 08:22

1 Answers1

0

Try DefaultTableCellRenderer.getTableCellRendererComponent() to customize the look and feel of cell item.

Sample code:

public class CustomTableCellRenderer extends DefaultTableCellRenderer {
    public Component getTableCellRendererComponent(JTable table, Object obj,
            boolean isSelected, boolean hasFocus, int row, int column) {

       JLabel label = (JLabel) super.getTableCellRendererComponent(table, obj, isSelected,
                hasFocus, row, column);

       label.setText(some_html_code_that_look_like_hyperlink);
    }
}
Braj
  • 46,415
  • 5
  • 60
  • 76