Extreme Java When vanilla Java is not enough

31Mar/080

Tooltip on JTable cells (take 2)

In a previous post, I explain how to add tooltips to JTable cells. Armand Bendananff told, in a comment, that a better way is to override the table's getToolTipText method as in:

public String getToolTipText(MouseEvent event) {
  Point p = event.getPoint();
 
  // Locate the renderer under the event location
  int colIndex = columnAtPoint(p);
  int rowIndex = rowAtPoint(p);
 
  String tooltip = "some value based on the row/col";
  return tooltip;
}
Tagged as: , No Comments