Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CrossHair cursor that extends to the boundaries of JPAnel

 
Jeevitha Jayaraman
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic