• 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

MouseListener and coordinate display

 
Ranch Hand
Posts: 386
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was just wondering if anyone could help me check this code please.

It's supposed to display the coordinates of the mouse on a JLabel when clicked, but it doesn't register if the mouse is moved even slightly while clicking. I've written vaguely similar code (but storing the dimensions locally and then calling repaint on the JFrame) with no such problem. Is there any reason why setting the text of a label should behave differently, or have I made a mistake somewhere?




am happy to paste the other code too if needed.

thanks,

Nick
 
Bartender
Posts: 5465
212
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Nick,

you are using 'mouseClicked'. That means you only get to hear
of a mouse click when the mouse button is released. Now,
if there is some distance between the location when the mouse
button was pressed and the location where it is released, then
mouseClicked is not invoked at all.

So, if you want some accuracy, use the methods 'mousePressed'
and 'mouseReleased'.
 
nick woodward
Ranch Hand
Posts: 386
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Piet Souris wrote:hi Nick,

you are using 'mouseClicked'. That means you only get to hear
of a mouse click when the mouse button is released. Now,
if there is some distance between the location when the mouse
button was pressed and the location where it is released, then
mouseClicked is not invoked at all.

So, if you want some accuracy, use the methods 'mousePressed'
and 'mouseReleased'.



thanks a lot! - i had completely missed that i'd used mousePressed in the other code!

Nick
 
reply
    Bookmark Topic Watch Topic
  • New Topic