Hi, I'm wondering if someone can verify the following code for me. I have an application that has a table with header. When I load my data for the application, this is done in a separate thread. While it's in this thread the mouse cursor is changed from default to WAIT. I've noticed that while the cursor is in WAIT mode, if the user moves the mouse over the header and crosses the separator from one column to another, the mouse cursor will forever be stuck in WAIT mode (but only in the header area). I believe this is because when the mouse crosses the separator, the mouse changes to a left/right arrow while it's over the separator. This appears to throw the mouse out of whack, so that when you attempt to return the mouse cursor to a normal pointer, it's unable to do so while the mouse is over the table header. Everywhere else in the application it has returned to normal except in the table header. I've attached the following code to demonstrate:
Thanks,
--------------------------------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
public class Main {
/** Creates a new instance of Main */
public Main() {
}
private static class RunThread implements Runnable {
private javax.swing.JFrame mainFrame;
public RunThread(javax.swing.JFrame frame) { mainFrame = frame; }
public void run() {
try {
mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
Thread.sleep(5000);
(mainFrame).setCursor(Cursor.getDefaultCursor());
System.out.println("Cursor Should have Returned to Normal here");
}catch(Exception e){} ;
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
final JFrame mainFrame = new JFrame("Test Frame");
mainFrame.setSize(500,500);
Container c = mainFrame.getContentPane();
c.setBackground(Color.GRAY);
c.setLayout(new FlowLayout());
// Add JTable
Object[][] data = {{"row1","row2"}};
String[] columnName = {"Press Here","Pause in Separator"};
JTable table = new JTable(data,columnName);
JTableHeader header = table.getTableHeader();
mainFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
mainFrame.dispose();
System.exit(0);
}
});
header.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
new Thread(new RunThread(mainFrame)).start();
}
});
c.setLayout(new BorderLayout());
c.add(header,BorderLayout.NORTH);
c.add(table,BorderLayout.CENTER);
mainFrame.setVisible(true);
}
}