Setting a JTable to display tooltip is easy. But what if a JTable cell’s text is not truncated? A tooltip should only appear whenever a cell text is truncated which is denoted by three dots …

To add this functionality in a JTable object, you would need to get the cell width and compare it with the text’s width based on its font by using the FontMetrics class. Place this code insider the getTableCellRendererComponent() method of a TableCellRenderer object.

There you go. The tooltip will only appear when your mouse cursor hovers over a JTable cell where the text is truncated.

Related Posts Plugin for WordPress, Blogger...