• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

CrossHair cursor that extends to the boundaries of JPAnel

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic