• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Can't set cursor on a JButton

 
Ranch Hand
Posts: 44
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Best, forum!

I have encountered a huge problem. I am trying to set the cursor on a JButton object to Cursor.HAND_CURSOR from the default state when the mouse
enters the object in question but somehow it fails. The buttons enability is set to false and at first i was wondering if the cause to the problem had
something to do with that but previously in the application i have managed to set the cursor to different states but in this case it doesn't work anymore.
I am just wondering  if anyone else has encountered this very same problem and what would be the general solution for this?

The code for my JButton object looks like this:



Any hints or thoughts are greatly much appreciated!

Kind regards,
Robert!

 
Robert Ingmarsson
Ranch Hand
Posts: 44
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, ranch!

I just solved it!



Weird, that one must use getRootPane() on the object before calling setCursor ...

regards,
Robert!
 
Saloon Keeper
Posts: 3300
146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Robert,

Well, if I use this MouseAdapter and add it to the button:

it works without any problems. Can you show us your MouseLIstener?
 
Robert Ingmarsson
Ranch Hand
Posts: 44
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Piet!

This is my MouseListener method that i use on the JButton object in question:



The MouseListener is implemented by a class called CompanyInfoPanel. Many thanks for the reply.

//Regards,
Robert!

 
Piet Souris
Saloon Keeper
Posts: 3300
146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Robert,

well, I see nothing wrong with your code. I copied it as much as I could, but it worked flawlessly. And enabling/disabling of the button does not matter for the working of the MouseListener, as you write. The only two things that I can think of, without knowing your code, is that there are circumstances where the icon is null (what has the icon got to do with this though?), or that you somehow have removed the MouseListner. Can you see if one of these happens somewhere?

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!