Results 1 to 8 of 8
  1. #1
    imorio is offline Senior Member
    Join Date
    Aug 2010
    Posts
    127
    Rep Power
    0

    Default getting rid of the system cursor

    I'm making a game where the user controlls a blue circle. I used the mouseMotionListener class to get the circle to follow the mouse, but how do I hide the original system mouse? It must be possible somehow using the Cursor class, but I can't figure it out.

    PS: yes I know it is possible to change the mouse in the circle, but just making the circle follow the mouse is easier for me. Also this give me more controll over where the circle is.

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    The Cursor class is the way to go - you can change the mouse to anything you want. There are many tutorials on this subject, this was the first google result:Displaying a Busy Cursor in Java

  3. #3
    imorio is offline Senior Member
    Join Date
    Aug 2010
    Posts
    127
    Rep Power
    0

    Default

    Yes, changing it to a busy cursor or a move cursor isn''t hard. The hard part is getting the cursor to disappear completly. The "createCustomCursor
    " methode of the toolkit class should help, but it is in an abstract class and isn't static. So I need an object implementing toolkit to do it. But how?

  4. #4
    imorio is offline Senior Member
    Join Date
    Aug 2010
    Posts
    127
    Rep Power
    0

    Default

    Ok, on my own I got till this stage:

    Java Code:
    Toolkit T=Toolkit.getDefaultToolkit();
    setCursor(T.createCustomCursor(null, new Point(0,0),"empty"));
    It won't accept null at the place it wants an Image, but it does say in the API that when the image is invalid, it will hide the cursor. So does anyone know how to make an invalid image?

  5. #5
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    You can just replace it with a transparent 1x1 pixel png.

  6. #6
    imorio is offline Senior Member
    Join Date
    Aug 2010
    Posts
    127
    Rep Power
    0

    Default

    But that would mean I need another file next to my .jar file (sending the program to someone would require sending 2 files if not zipped). It is possible, but not the ideal solution. It sounds way to much like a hack. Isn't there a way you are supposed to get rid of the system cursor? A specific way the developers designed to be used to get rid of the cursor?

  7. #7
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    You can put all libraries/images/resources etc. inside your jar file. No need for it to be external. And... this isn't really a hack. Example: java - How to hide cursor - Stack Overflow

  8. #8
    imorio is offline Senior Member
    Join Date
    Aug 2010
    Posts
    127
    Rep Power
    0

Similar Threads

  1. Cursor image
    By PhQ in forum New To Java
    Replies: 5
    Last Post: 10-05-2010, 07:49 PM
  2. Show Cursor
    By PhQ in forum AWT / Swing
    Replies: 3
    Last Post: 09-01-2010, 08:23 PM
  3. change the mouse cursor - crosshair cursor
    By cassysumandak in forum New To Java
    Replies: 1
    Last Post: 09-28-2009, 01:57 AM
  4. Cursor
    By serfster in forum New To Java
    Replies: 2
    Last Post: 06-15-2008, 05:49 AM
  5. Using a cursor
    By notnumber6 in forum New To Java
    Replies: 3
    Last Post: 11-26-2007, 10:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •