This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes custom cursor in XOR mode Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "custom cursor in XOR mode" Watch "custom cursor in XOR mode" New topic

custom cursor in XOR mode

Amit Agarwal
Ranch Hand

Joined: May 09, 2001
Posts: 92
I am using a custom crosshair cursor generated with a gif file containing the image. Is it possible that the cursor be shown in XOR mode, as can be seen in many graphics applications. i.e. the cursor (which is white in color) draws itsself in black wherever there is a white area on the panel.
Thanks in Advance
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

Hmmm... Java doesn't support this behavior directly, as far as I know... but I think you could do it yourself. All you would have to do is set the "real" cursor to an invisible cursor, and draw the crosshairs on the frame yourself using XOR mode ( the Java Graphics object supports this... ), using a mouseListener to get the x and y coordinates of where it should be drawn.

Here's some code I was testing this concept on... hope it helps you out some...

( Note: "NoCursor.gif" is just a 16 x 16 transparent gif. )

[This message has been edited by Nathan Pruett (edited June 28, 2001).]

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Amit Agarwal
Ranch Hand

Joined: May 09, 2001
Posts: 92
Hi Nate,
Thanks for your help, but this will be difficult to implement in my application as my paint() method is very heavy, and i am looking forward to make minimum calls to it. If this method is used I will have to call the paint everytime the mouse moves to erase the previous cursor drawing.
I agree. Here's the link:
subject: custom cursor in XOR mode
It's not a secret anymore!