• 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

Changing Cursor Icon

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
ImageIcon doing
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.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Leonard Connoway wrote:If I do this, I get an error...


So what does the error say?
 
Ranch Hand
Posts: 91
IntelliJ IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And what is error you are getting before the program crashes?
 
Leonard Connoway
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Line 73 of GUI is
 
Vineeth Menon
Ranch Hand
Posts: 91
IntelliJ IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not really sure about this one, it's a shot in the dark actually. It seems the MouseInfo.getPointerInfo().getLocation()

is not getting the hotspot's X and Y co-ordinates. I'd say Specify a Point give it a 'X & Y' value...something like

Point hotSpotPoint = new Point(0,0,);

and pass the hotSpotValue rather than MouseInfo.getPointerInfo().getLocation()
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok thank you all. That is working; however, 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?
 
Vineeth Menon
Ranch Hand
Posts: 91
IntelliJ IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Leonard Connoway wrote:Ok thank you all. That is working; however, 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?


You need to use a bigger image for the cursor
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vineeth Menon wrote:

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
 
Leonard Connoway
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you can tell us what you are trying to achieve, we will be able to be of assistance
 
Leonard Connoway
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you hide the cursor (empty image) how do you expect the user to recover from that stage? It is certainly bad usability. What's wrong with providing your own image for the cursor?
 
Leonard Connoway
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might want to consider a tooltip or a popup instead.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic