I came across this since it was similar to what I needed - I wanted to put in tooltips for the column headers. The Oracle demo example linked by camickr enabled tooltips by additional code in the JTable creation. That example steered me in the right direction, and I got it working similarly, but that way of doing it was initializing a new JTable every time the table was updated. Before, I was just using myJTable.setModel() to update the table. Plus the Oracle example looked messy and was confusing for a bit there. I didn't need to extend AbstractTableModel since it didn't look like it affected tooltips at all.
So how could I get column header tooltips without making a new JTable each time and without the mess? The crucial code in the JTable initialization was overriding a method in the JTable "protected JTableHeader createDefaultTableHeader()" which of course allows for a table header (JTableHeader) with tooltips. The JTableHeader is what I really wanted to work on.
What I did is I created a new class that extended JTableHeader so that it included a tooltips String array in the constructor and a getToolTipText() method (same as the example except with out the String tip), and then I did myJTable.setTableHeader() to set it to an instance of my new class that has the tooltips String array.
(I'm posting this as an answer since it's too involved for a comment, but could be useful to others)
Here is the code in my GUI class when I update the table-
myJTable.setModel(new javax.swing.table.DefaultTableModel(
tableData,
colHeader
));//setting the new data and col headers! (no tooltips yet)
MyTableHeader headerWithTooltips = new MyTableHeader(myJTable.getColumnModel(), colHeaderTooltips);//make a new header that allows for tooltips
myJTable.setTableHeader(headerWithTooltips);//use that header in my table
And here is my MyTableHeader class-
class MyTableHeader extends JTableHeader {
String[] tooltips;
MyTableHeader(TableColumnModel columnModel, String[] columnTooltips) {
super(columnModel);//do everything a normal JTableHeader does
this.tooltips = columnTooltips;//plus extra data
}
public String getToolTipText(MouseEvent e) {
java.awt.Point p = e.getPoint();
int index = columnModel.getColumnIndexAtX(p.x);
int realIndex = columnModel.getColumn(index).getModelIndex();
return this.tooltips[realIndex];
}
}