Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Changing mouse pointer using setCursor()

843806Nov 12 2008 — edited Nov 12 2008
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 10 2008
Added on Nov 12 2008
6 comments
706 views