Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

MouseMotionListener and JButtons  RSS feed

 
Aran Winters
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

I'm having difficulty getting any events generated when passing over JButtons.
I've added the listener to the underlying container. Below is a trivial app designed to give the minimum code necessary to convey my larger problem.

I'm sure that I'm just overlooking something, but advice/help would be appreciated.

Thanks,

/Aran


 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you change this
temp = getComponentAt(e.getX(),e.getY());

to this
temp = findComponentAt(e.getX(),e.getY());

it works, but the cursor has to be a bit under the components
probably needs to factor in the height of the title bar
 
Pat Hays
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JButtons should add MouseMotionListener as well.
 
Aran Winters
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to you both,

I've only tried the first solution (changing getComponentAt() to
findComponentAt() and it definitely works with the caveat of needing
the mouse to be slightly below the component. Unfortunately, My lil
app needs to be firing events when cursor is directly over, so I'm
working on solution 2 -- adding mousemoition listeners to the buttons.

Thanks again,

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