I am attempting to change a cursor's icon upon clicking a button, but I seem to be having trouble getting NetBeans to read in the image.
If I do this, I get an error and the program crashes upon clicking the button. I know that the image is valid though because I created an
and created a JLabel with that, and it is showing the image properly. Additionally, I tried to get the image using
This won't crash the program, but when you click the button, the cursor turns invisible instead of into the image.
Any help would be much appreciated.
The "hotspot" point represents the pixel location in the cursor image where the click happens. E.g. for an arrow image cursor, it is typically the arrow point. Now do you see why you are getting the exception? Hint: What does MouseInfo.getPointerInfo().getLocation() return?
Leonard Connoway wrote:... the cursor is way too small for what I am trying to do, so does anyone know of a way I can make it larger?
Well I guess the hotspot's X and Y axis is the answerl, try to give a bigger number in the X & Y axis, and you ought to have a bigger cursor.
No. Like I mentioned earlier,the hotspot is the point where the "click happens" in the cursor image co-ordinate system. It does not define the cursor size.
e.g. For an "arrow cursor", hot spot should be the arrow point. For an image of arrow titled left this will probably translate to 0,0. For a cross hair cursor, of say 32x32, the hot spot would be the intersection point of the cross hair, which would be 16,16
What I am planning on doing is changing the cursor into an empty image, and then I will create a JLabel with the desired image
that will have a timer event to constantly move to where the cursor is, unless somebody has a better idea.
What I intend to do is have the cursor change to a certain image depending on what component you click on; however, I need to make the cursor image larger than 32x32. After reading a few other things online, the easiest way I have found would to just have a JLabel with the larger images move to the cursor's location on a timer to make it appear that the JLabel is the cursor.
If I make a custom cursor and give it the desired image, it will shrink the image to 32x32, but I want it much larger. Upon clicking the appropriate button though, it will set the cursor back to the default image and make the following JLabel invisible.