Hi- I've got a single threaded JFrame-based application in which I want to change the mouse pointer to indicate 'busy' when it's doing stuff eg. loading a file. So within my extended JFrame method for handling menu selections I've got:
public class Layout extends JFrame
{
// For items in the main menu
// (the sub-class contains either a JMenuItem or JCheckBoxMenuItem).
abstract class MenuItem implements ActionListener
{
abstract JMenuItem menuItemAbs(); // get the menu item component
abstract void handlerAbs(); // perform the menu's action
// Menu item has been selected.
public void actionPerformed(ActionEvent e)
{
Cursor cursor = Layout.this.getCursor();
Layout.this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
handlerAbs();
Layout.this.setCursor(cursor);
}
But the mouse pointer doesn't always change. If handler() just does some processing without user interaction, the pointer does change. But in the case of loading a file, where first the user selects the file using a JFileChooser, it doesn't.
Is this because JFileChooser does its own setCursor()? But even if it does, presumably it does another setCursor() to restore my WAIT_CURSOR before it returns, so why don't I see the WAIT_CURSOR while the file is loading (which takes seconds)?
Cheers
John
EDIT: BTW running under Linux, Java v6 update 7
Edited by: matth1j on Nov 12, 2008 2:15 AM