Changing mouse pointer using setCursor()

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

Ok, thanks - full demo program below.
When you hit the ok button (just 5 second sleep), the mouse pointer changes to 'busy'. It reverts to normal if you move the pointer off the frame, but goes back to 'busy' if you move it back onto the frame.
When you hit the bad button (brings up file chooser, then does 5 second sleep), the pointer changes to 'busy' while the pointer is over the frame, and reverts to normal when the pointer is moved off the frame. But if you select a file or cancel the file chooser and move the pointer back into the main frame before the 5 seconds is up, the pointer doesn't go back to 'busy' again. I would expect it to show 'busy' while over the frame until the 5 seconds is up.
Any ideas?
package test;
import java.awt.Cursor;
import java.awt.EventQueue;
import java.awt.event.*;
import javax.swing.*;
public class Main
    public static void main(String[] args)
        EventQueue.invokeLater(new Runnable()
            public void run()
                new Test();
class Test extends JFrame
    public Test()
        super();
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        JPanel panel = new JPanel();
        panel.add(new Button("ok"));
        panel.add(new Button("bad"));
        add(panel);
        pack();
        repaint();
        setVisible(true);
    class Button extends JButton implements ActionListener
        Button(String text)
            super(text);
            addActionListener(this);
        public void actionPerformed(ActionEvent e)
            Cursor cursor = Test.this.getCursor();
            Test.this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            if (!e.getActionCommand().equals("ok"))
                (new JFileChooser()).showOpenDialog(null);
            try
                Thread.sleep(5000);
            catch (Exception ex)
                ex.printStackTrace();
            Test.this.setCursor(cursor);
}Edited by: matth1j on Nov 12, 2008 2:44 AM code tidy
Edited by: matth1j on Nov 12, 2008 2:45 AM code tidy

Similar Messages

  • Change mouse pointer over selected text

    I have a JTextArea and i want to change the default mouse pointer to the arrow pointer when the user points to a selected text. Just like the way JCreator works.!
    Thanx

    Try this :
    Cursor textCursor = new Cursor(Cursor.TEXT_CURSOR);
    Cursor arrowCursor = new Cursor(Cursor.DEFAULT_CURSOR );
    textArea.setCursor(textCursor);
    textArea.addMouseMotionListener(new MouseMotionAdapter() {
         public void mouseMoved(MouseEvent e) {
              int location = textArea.viewToModel(e.getPoint());
              if (textArea.getSelectionStart()<=location && location<textArea.getSelectionEnd()) {
                   if (textArea.getCursor() != arrowCursor) {
                        textArea.setCursor(arrowCursor);
              else {
                   if (textArea.getCursor()==arrowCursor) {
                        textArea.setCursor(textCursor);
    });I hope this helps,
    Denis

  • Changing mouse pointer

    I would like to be able to change my mouse pointer to something
    other that what set_application_property cursor_style can do for
    me. I would like to be able to call a mouse pointer from the
    file system and replace the the pointer in my forms app.
    Thanks in advance for any direction that can be given.
    Roland

    If your Mouse cursor is in a DLL you can do:
    Set_Application_Property(CURSOR_STYLE,'<DLLNAME>cursorname');
    For this to work you have to load the above DLL first using
    ORA_FFI.LOAD_LIBRARY().

  • Change Mouse Pointer Look

    Hi,
    I have a show/hide layers behavior setup on an image - when
    the image is clicked. It works just fine. However, when you hover
    the mouse over the image, the mouse pointer doesn't change to the
    hand, like it would with a link. Is there any way to get the mouse
    pointer to change to the hand when it is hovering over the image?
    Thanks,
    Lynn

    Open the page in DW. Select the image and look at the
    behaviors panel.
    Change the Event from onClick to <A> onClick, using the
    drop-down list of
    events in the behaviors panel.
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "L Gamble" <[email protected]> wrote in
    message
    news:e7hifj$6r6$[email protected]..
    > Hi,
    >
    > I have a show/hide layers behavior setup on an image -
    when the image is
    > clicked. It works just fine. However, when you hover the
    mouse over the
    > image, the mouse pointer doesn't change to the hand,
    like it would with a
    > link.
    > Is there any way to get the mouse pointer to change to
    the hand when it is
    > hovering over the image?
    >
    > Thanks,
    > Lynn
    >

  • Changing unloading point using BAPI

    Hello Gurus,
                         Can we change unloading point(item level) in the sales order using BAPI_SALESORDER_CHANGE. If so please let me know how to do it.
    Thanks,
    KB

    Did you use BAPI_TRANSACTION_COMMIT after BAPI_PO_CHANGE.
    Look also at this <a href="http://www.sap-img.com/abap/sample-abap-code-on-bapi-po-change.htm">Sample Abap code on BAPI_PO_CHANGE</a>
      CALL FUNCTION 'BAPI_PO_CHANGE'
        EXPORTING
          PURCHASEORDER = T_POHEADER-PO
          POHEADER      = T_BAPI_POHEADER
          POHEADERX     = T_BAPI_POHEADERX
        TABLES
          RETURN        = T_BAPIRETURN
          POITEM        = T_BAPI_POITEM
          POITEMX       = T_BAPI_POITEMX.
      READ TABLE t_bapireturn WITH KEY type = c_err TRANSPORTING NO FIELDS.
      IF sy-subrc NE 0.
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
          EXPORTING
            wait = c_x.
      ENDIF.
    Regards

  • How to change mouse pointer

    I would like enlarge or change the color of the mouse pointer.  Can anyone help

    No, they didn't. I am running 10.7.3.

  • How to change mouse pointer to Arrow?

    When we move the mouse over any component in preview (or in SWF file), mouse pointer changes to u201Chandu201D. Is it possible to keep the mouse pointer to Arrow or any other custom mouse pointer in Xcelsius 2008 SP 4?
    Thanks

    Mouse over cursor is set to ARROW if the component is not selectable
    Eg:pie chard which has no drill down or no furthur selection is enabled then the mouse over by default is ARROW.
    If you have enabled any furthur selection for that component the by default mouseover is HAND .
    This holds good for all the components in Xcelsius (even in sp4) Except for tab set container component where the selection of tabs is displayed with Arrow  symbol.
    New features that sp4 provides is 1)Waterfall chart 2)Alerts are  supported for spreadsheet tables, and for
    combination charts.
    @Sri

  • Change mouse pointer for Assessment Simulation

    Hi there-
    I have an assessment simulation - and I need the users mouse
    pointer to change to a crosshair (I think that's what it's called)
    when the mouse is over a certain area on the screen. Is there
    anyway to do this? I know it can be done in a demonstration for the
    pointer in the demo.
    Lynn

    Authorware allows access to the system's mouse 'library', but
    it also
    allows full Windows File System access too...which could have
    security
    issues. So it's certainly possible...but, agreed, who knows
    whether such
    functionality would be integrated into CP.
    Erik
    CatBandit wrote:
    > Can't be done, Lynn, but what a great idea for a new
    feature!!
    >
    http://www.adobe.com/cfusion/mmform/index.cfm?name=wishform&product=15&6213=9.[/
    > b]
    >
    > The way I see it, you could select the mouse-pointer
    you want displayed on the
    > user's machine from the mouse-properties dialog. But
    wait! Now that I' said
    > that, it occurs to me that any security program worth a
    hoot might
    > automatically block this, as it requires access to
    Windows system files . . .
    >
    > Well, it's still worth requesting, and I think the
    developers could figure a
    > way around the security problems if there are any. Have
    a great day!
    > .
    >
    Erik Lord
    http://www.capemedia.net
    Adobe Community Expert - Authorware
    http://www.adobe.com/communities/experts/
    http://www.awaretips.net -
    samples, tips, products, faqs, and links!
    *Search the A'ware newsgroup archives*
    http://groups.google.com/group/macromedia.authorware

  • Change Mouse Pointer Shape

    Is there any way to change the shape of the cursor by using applescript?
    My script is doing some work wich can require a number of seconds to complete. I would like the user to be informed by changing the shape of the pointer to the standard waiting animation used by OS X.
    Thanks in advance

    If you are referring to the spinning rainbow wheel, that is not a wait cursor, that is "the application is not responding" indicator. To follow Apple's Human Interface Guidelines, you should use a progress indicator - my preference is the BP Progress Bar.

  • Problem with i-Planet and change mouse cursor

    Hello, I know how change mouse cursor using Toolkit.getdefaultToolkit().createCustomCursor(Imagen,new Point(0,0),String) and setCursor. It works in a local applet but it doesn`t in my aplication. This aplication attach a i-Planet web server and displays the following error:
    java.lang.NoSuchMethodError: java/awt/Toolkit: method createCustomCursor(Ljava/awt/Image;Ljava/awt/Point;Ljava/lang/String;)Ljava/awt/Cursor; not found
    Where's the problem? Maybe an incorrect jdk version. I don�t think so because I use 1.3.1 version and this method works since 1.2 version.
    Thank you for all.

    hi,
    iplanet has its own jar files in \Netscape\Server4\bin\https which contains the same jar files as it is in jdk dir...so importing ur jar files thru the environment might create a similar problem

  • Mouse pointer snap range

    Can anyone advise if I can change the snap range (number of screen pixels around a graphics point) for the mouse pointer. I use a CAD program and need to increase the area on screen that the mouse pointer uses to pick up points etc. With the increased screen
    resolution the area (number of pixels) that the mouse pointer needs to be in to find a point gets smaller all the time and there is no provision in the software to increase the target area pixels.
    Regards
    Mark

    Hi Mark
    As I know,CAD programs should have related settings in options Dialog Box. You should be able to set the display size for the object snap target box in pixels. You could contact with program manufacturers check on this.
    This kind of settings might not come with Winodws, Windows provide basic driver for devices, Manufacturers might offer advanced driver program for their products. You also could download these program to modify these settings such as DPI.
    We suggest you modify these settings in your CAD program so it can only affect the usage in CAD.
    Regards
    D. Wu

  • Lenovo G550 - Keyboard/Mouse/Pointer Issues - PLEASE HELP Tech suppport couldn't.

    I spent over an hour on the phone with Lenovo tech support last week to try to solve this issue and it is not solved. The guy had never heard of it and kept researching how to fix it.  I personally  have this feeling that it's a very very simple issue but I can't figure out how to correct it.  I've changed mouse/pointer settings and it still isn't working.  I love my new laptop in every other way but i'm getting so frustrated with it I'm ready to send it back because of the problem with the mouse/pointer.  So if anyone could help me I'd appreciate it greatly.
    I will be typing and out of nowhere the cursor will move to wherever the mouse is...or it will highlight everything I just typed and delete it.  I've had to type much slower and keep moving the mouse but when i'm working on my projects and typing away and highlighting/editing, I get into the work and it's a pain in the rear when the cursor suddenly moves a paragraph up and I am still typing away and sometimes don't realize it until i've typed another two sentences.  Hence the typing slower.
    Today it deleted discussion posts I had typed up for my online classes before I had hit submit. Causing me to waste another 30 minutes trying to retype what I'd already done.  I was ready to throw this laptop in the garbage.
    I decided to not do that and post in this forum in the hopes that someone will be able to help me.
    Thank you,
    Komal

    @ shelagh
    try to un-install touchpad drivers,restart your computer and check if issue persists.
    and/or try to flash bios update ( for bios update, read readme file first )
    http://consumersupport.lenovo.com/us/en/DriversDownloads/drivers_list.aspx?CategoryID=600154

  • Mouse pointer rather slow

    After changing mouse pointer acceleration in control panel to maximum, mouse pointer is faster, but still rather slow. At least slower, than it is with windows7. In windows7 it´s one move from left to right. In Windows10 I have to move twice. It´s an asus
    notebook with mouse-pad.

    Hi poet-man,
    If you mean the mouse-pad device, I suggest you check if there are any latest driver for it.
    If you upgrade from previous operating system, it is recommended to uninstall the device from device manager restart your PC to check how it works.
    Alex Zhao
    TechNet Community Support

  • Mouse pointer shape changing

    Hello....
    I have a panel . on this panel a rectangle is drawn by using 2D graphics... i want to change the mouse cursor when the mouse is in the middle of the rectangle and also change when the mouse is on a side of the rectangle. to show user that when he/she take the mouse pointer at the side of the rectangle then it will be drag mode..please give a example code...thank you

    It sounds like you'll need to use the setCursor method of your JPanel along with a MouseMotionListener to pick up when the cursor is moved over the drawn rectangle.

  • Change the mouse pointer to an Hour glass

    hello,
    Could any one of you let me know how to make mouse pointer to an hour glass in swing application.
    Thanking you in advance..
    Ram

    Check out how I do this in my Draggable classs
    you are welcome to use and modify this class, but please don't change the package or take credit for it as your own work
    package tjacobs.ui;
    import java.awt.Component;
    import java.awt.Cursor;
    import java.awt.Dimension;
    import java.awt.Point;
    import java.awt.Window;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionListener;
    * tjacobs.ui.Draggable<p>
    * Makes a component draggable. Does not work if there's a layout manager
    * messing with things<p>
    * <code>
    *  usage:
    *                 Component c = ...
    *                 new Draggable(c);
    *                 parent.add(c);
    *  </code>
    public class Draggable extends MouseAdapter implements MouseMotionListener {
        Point mLastPoint;
        Component mDraggable;
        public Draggable(Component w) {
            w.addMouseMotionListener(this);
            w.addMouseListener(this);
            mDraggable = w;
         public Draggable(Window w, Component drag) {
              drag.addMouseMotionListener(this);
            drag.addMouseListener(this);
              mDraggable = w;
        public void mousePressed(MouseEvent me) {
              if (mDraggable.getCursor().equals(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR))) {
                   mLastPoint = me.getPoint();
              else {
                   mLastPoint = null;
         private void setCursorType(Point p) {
              Point loc = mDraggable.getLocation();
              Dimension size = mDraggable.getSize();
              if ((p.y + WindowUtilities.RESIZE_MARGIN_SIZE < loc.y + size.height) && (p.x + WindowUtilities.RESIZE_MARGIN_SIZE < p.x + size.width)) {
                   mDraggable.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        public void mouseReleased(MouseEvent me) {
            mLastPoint = null;
        public void mouseMoved(MouseEvent me) {
              setCursorType(me.getPoint());
        public void mouseDragged(MouseEvent me) {
            int x, y;
            if (mLastPoint != null) {
                x = mDraggable.getX() + (me.getX() - (int)mLastPoint.getX());
                y = mDraggable.getY() + (me.getY() - (int)mLastPoint.getY());
                mDraggable.setLocation(x, y);
    }

Maybe you are looking for

  • Macbook pro no sound

    I have tried every resource on the net... can anyone help? sound works when i turn on the mac but anything eles I get the circle with a slash and there is no adjustment or sound when I turn up or down. I bought this new in 08 and this is the only pro

  • Print a new report whenever a change occurs to data field

    Post Author: goffj1 CA Forum: General Feedback Please forgive my ignorance but this is my first experience with CR.  I have a dynamic dataset with multiple records.  Each records contains a TASK number that groups all the records relating to that TAS

  • Will Adobe produce RAW 8.6 for Elements 12?

    Having just got a Panasonic Lumix DMC-FZ1000, Elements 12 can't process its RAW files. The Adobe site says RAW 8.6 which will process them is only available with full blown Photoshop

  • Can't connect to my HP Laserjet 5 printer anymore

    I moved into my newly built house, and after setting back up my home office, I can no longer connect to my (i know it is old) HP Laserjet 5 printer with my iMAc, running OS x 10.6.8. I am on a small in house network, and can't even see the printer, l

  • Big problem accessing icloud account

    We have multiple devices connected to our iCloud account and just logged out using our Mac system. All devices are happily using iCloud but we can not log back into our account on the Mac and are told a mix of Can't log on at this time and ID and pas