Setting the mouse cursor for a specific JTable cell

I have a JTable with a set of non-editable cells, and I want all the cells in a specific column to display a different mouse pointer while the mouse is hovering over them. I already use my own renderer, and setting the cursor on the rendering component does not work (as well as for tooltips).

It seems to work for editors.

Is this not possible in JTable when your cell is not being edited or am I missing something?

+5
source share
2 answers

Add MouseMotionListener to JTable, and then in mouseMoved (), determine which column is using JTable columnAtPoint (), and if this is the specific column that you are using, setCursor () in JTable.

+7
source

Here is one way to change the cursor in a specific column in JTable:

if(tblExamHistoryAll.columnAtPoint(evt.getPoint())==5)
{
    setCursor(Cursor.HAND_CURSOR); 
}
else
{
    setCursor(0);
}
0
source

All Articles