5

I want to re-use the current Mouse Pointer. I want to use the current selected mouse Pointer image and want to underlay another image. The application is written in java

the idea is, i have a tool bar and when i use the save-tool, the cursor should be a custom tool-image (disk) and over this the mouse pointer image provided by the underlying operating system.

creating custom curso image

so far i know how to change a cursor:

Toolkit toolkit = Toolkit.getDefaultToolkit();
Image image = toolkit.getImage("images/diskimage.gif");
Point pointerPos = new Point(1,1);
Cursor c = toolkit.createCustomCursor(image , pointerPos, "cursorname");
myPanel.setCursor (c);

and i know how to paint images on each other, so i can create a merged image. the problem is, that i don't want to use custom cursor images, but instead enhance the cursors that are already in use.

--> but how can i get the image from the cursor from the underlying operating system?

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Martin Frank
  • 3,445
  • 1
  • 27
  • 47
  • Can you do something with [getPredefinedCursor](http://docs.oracle.com/javase/7/docs/api/java/awt/Cursor.html#getPredefinedCursor%28int%29)? – DavidPostill Jul 30 '14 at 11:06
  • 1
    i get even the cursor from my panel, JPanel myPanel = new JPanel();
    myPanel.getCursor()
    but how can i draw this cursor?
    – Martin Frank Jul 30 '14 at 11:09
  • 1
    Possible duplicate of [Extract cursor image in Java](http://stackoverflow.com/a/740528/3536342), this answer shows how to load windows cursor as a Java image using JNI – DavidPostill Jul 30 '14 at 11:18
  • 1
    yes, maybe a duplicate... but in that posts you get the pointer image via native code using win32api... i was looking for a way without that... – Martin Frank Jul 30 '14 at 11:24
  • I don't think it's possible without native code ... :/ – DavidPostill Jul 30 '14 at 11:28
  • 1
    ok, thanks a lot - i tried the robot to create a snap shot - but on the screen capture is no mouse pointer visible... – Martin Frank Jul 30 '14 at 11:35
  • 1
    very frustrationg - the jna/jni approach from @McDowell from Extract cursor image in Java, works perfectly... but still, i'm quite annoyed to do such work around - i'm grateful that you lead me to the right path, thanks man, really!!! – Martin Frank Jul 30 '14 at 12:35
  • Any luck with that? I know that it's a very old post, but still the answer might be useful... – Panayotis Sep 04 '16 at 18:25
  • @Panayotis what worked was the approach from McDowell: http://stackoverflow.com/questions/739870/extract-cursor-image-in-java/740528#740528 – Martin Frank Sep 05 '16 at 04:24
  • @MartinFrank thank you, I was hoping for some kind of more OS-independed solution but it seems I'm out of luck. Thus I might need to have a look at linux/OS implementations too and it already sounds like hell. – Panayotis Sep 06 '16 at 17:08
  • @Panayotis i'm really sad to hear that :-/ – Martin Frank Sep 07 '16 at 05:50

0 Answers0