aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes CrossHair cursor that extends to the boundaries of JPAnel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "CrossHair cursor that extends to the boundaries of JPAnel" Watch "CrossHair cursor that extends to the boundaries of JPAnel" New topic
Author

CrossHair cursor that extends to the boundaries of JPAnel

Jeevitha Jayaraman
Greenhorn

Joined: Oct 17, 2008
Posts: 3
Hi Friends,

I am designing a Drawing tool and I have a requirement for a custom crossHair that will extend till the boundaries of the JPAnel on all sides.

What I have done now is to draw two lines across the cursor point in MouseMove event. This works fine but this does not replace the default cursor and calls the repaint for each mouseMove and this seems inefficient.

I know that there is a customCursor where we can have a image. But I do not find a possibility of using images here, since the needed cursor is big and the image size would overlap the panel completely hiding the drawings.

The other option that I can think of is to extend the Cursor class and create my own cursor. But I do not know what methods to override and how to go about it.
Please help me if you have ideas on extending a Cursor class or If you can find any other better solution. Thanks
Mikko Kohtamäki
Ranch Hand

Joined: Dec 13, 2008
Posts: 112
Hi,

calls the repaint for each mouseMove and this seems inefficient.

Indeed...
But I do not find a possibility of using images here, since the needed cursor is big and the image size would overlap the panel completely hiding the drawings.

You can paint the image with transparency.

Draw into BufferedImage, here couple of links for example
Creating a Buffered Image
Drawing on a Buffered Image

Now you only set cursor property on mouseOver events on whatever component


I forgot to ask, is it your requirement that the crosshair's centre point must be in cursor's location when moving the mouse?

If so then you could draw only a small part of the area on mouseMoved event determining if the mouse moved horizontally then you draw more vertically or mouse moved vertically you draw more horizontally through repaint(Rectangle) method call... dont know maybe someone has a better idea...

And in which component you are drawing this crosshair, in the actual JPanel or perhaps in glassPanel?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: CrossHair cursor that extends to the boundaries of JPAnel
 
Similar Threads
unable to change the cursor to string.
Drawing in XORMode or Layers?
custom cursor in XOR mode
Complex Page Layout
Image in place of buttons