Setting the mouse cursor for a particular JTable cell
-
05-09-2019 - |
Question
I have a JTable with a set of uneditable cells and I want all the cells in a particular column to have a different mouse cursor displayed whilst the mouse is hovering over them. I am already using a custom renderer and setting the cursor on the renderer component doesn't seem to work (as it does for tooltips).
It does seem to work for editors.
Is this not possible in JTable when your cell is not being edited or am I missing something?
Solution
Add a MouseMotionListener to the JTable and then on mouseMoved() determine which column it is using JTable's columnAtPoint() and if it's the particular column you are after, setCursor() on the JTable.
OTHER TIPS
Here is one way of changing the cursor at a particular column in JTable:
if(tblExamHistoryAll.columnAtPoint(evt.getPoint())==5)
{
setCursor(Cursor.HAND_CURSOR);
}
else
{
setCursor(0);
}