JTable.SetCursor not changing cursor
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);
}
}
});
May be when model changes columns model is changed as well and the old column instance isn't valid anymore.
Have set cursor through MouseMotionListener inside MouseMoved() method.
no, I think that there any reason for that
you can solve that
1) define the Cursor
for JScrollPane#setCursor()
if you need to recreate JTable
from its Model
2) stop to recreate JTable
(from your TableModel
) inside your code,
3) example for JTable
and Cursor
here
I had not set the owner of JFileChooser/Jdialog to the underlying panel. Hence, when these components came over, a new hierarchy was created and all painting operation started on this new hierarchy (something like this, but i'm not too sure).
When i set the owner of secondary panels as the main panel, on disposing these secondary panels, the modified cursor again started appearing on the main panel (might be due to the fact that a single paint hireracrchy was present now).
精彩评论