Author |
Messages |
converge
Corporal
Gender: Unspecified
Location:
Registered: Apr 2004
Status: Offline
Posts: 28
|
Posted Tuesday, October 21, 2008 @ 14:39:28
I'm trying to change the cursor when the user clicks on a column (table header). This seems to only work some of the times, randomly, with no rhyme or reason. Here is my code:
Code: | |
dbtResults.getTableHeader().addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
Thread.sleep(2000);
} catch (Exception e) {}
setCursor(Cursor.getDefaultCursor());
}
public void mouseReleased(MouseEvent evt) {}
});
|
|
|
Admin
Board Owner
Gender: Unspecified
Location:
Registered: Jul 2003
Status: Offline
Posts: 9
|
Posted Tuesday, October 21, 2008 @ 16:01:59
mouseClicked() method will be called in EventDispatcherThread, I am not sure what will be the impact of adding a sleep in EventDispatcherThread.
Try to add the cursor change in the following method
DBTableEventListener.onSortColumn(int column, boolean ascending) . This method will be called when user click the column header.
|
converge
Corporal
Gender: Unspecified
Location:
Registered: Apr 2004
Status: Offline
Posts: 28
|
Posted Wednesday, October 22, 2008 @ 10:13:44
Actually, I'm not supposed to use the Thread.sleep() call in my code. I only put it there to suspend the program long enough to see if the cursor changes or not. The real code should be:
Code: | |
dbtResults.getTableHeader().addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
dbtResults.sortByColumn(2, true);
setCursor(Cursor.getDefaultCursor());
}
public void mouseReleased(MouseEvent evt) {}
});
|
|
Basically, I want a "wait" cursor for when the table is sorting, and then to revert to the default cursor when it's done.
|
Admin
Board Owner
Gender: Unspecified
Location:
Registered: Jul 2003
Status: Offline
Posts: 9
|
Posted Wednesday, October 22, 2008 @ 14:28:10
Is the mouseclicked method getting invoked when you click the header?
Is it possible the sorting is fast, that the cursor is quickly switched back to default?
|
converge
Corporal
Gender: Unspecified
Location:
Registered: Apr 2004
Status: Offline
Posts: 28
|
Posted Wednesday, October 22, 2008 @ 14:33:41
Yes, the event is being called but the cursor is not changing. I'm sorting on ~200,000 rows so it actually takes around 3-4 seconds to perform. A client was complaining that they didn't know what was happening when they clicked the header because there was no cursor indication.
|
Admin
Board Owner
Gender: Unspecified
Location:
Registered: Jul 2003
Status: Offline
Posts: 9
|
Posted Monday, October 27, 2008 @ 08:43:03
Instead of calling dbtable.setCursor, you can get the Jtable used by Quicktable and try to set the cursor.
dbtable.getTable().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|