I've created a table, and setcursor on a particular column. The cursor is displayed properly for the first time when table is displayed, but if the table model changes and table is repainted, the cursor is not shown as per the code, instead, default cursor is shown on all columns.
Tried debugging the code, the call to jtable.setcursor gets executed properly, but cursor not displayed on screen.
Have set cursor through MouseMotionListener inside MouseMoved() method.
Any help appreciated.
My Recent Observation:
I have detected that the issue arises when any other dialog comes over the scrollpane that displays the table. If a JFileChooser or a JDialog is launched over a panel containing JScrollPane for JTable, after closing the JFileChooser or JDialog, the cursor on table is not displayed as per code, this is happening even in case when table model does not change at all.
Following is my code to set cursor:
final Cursor handCursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
final Cursor defaultCursor = Cursor.getDefaultCursor();
table.addMouseMotionListener(new MouseAdapter()
{
public void mouseMoved(MouseEvent e)
{
int cModel = table.columnAtPoint(e.getPoint());
int cView = table.convertColumnIndexToView(cModel);
if (cView == 1)
{
table.setCursor(handCursor);
}
else
{
table.setCursor(defaultCursor);
}
}
});