Mouse event type problem

  • Thread starter steve_marjoribanks
  • Start date
S

steve_marjoribanks

I would like to be able to draw a number of polygons as a
representative diagram of some coordinate data on a JPanel and then
when the mouse is moved over one of the polygons (into the area it
bounds) generate some event so that information in another JPanel is
updated to show the data about that polygon.
From what I've read, Swing mouse events can only be applied to
Components themseves, not items within them. Is there any possible way
of doing this? I guess I could use the mouse x,y coordinates to roughly
work out where the pointer is in relation to the objects on the JPanel
but is there an easier, more obvious way that I am completely unaware
of?!

Thanks

Steve
 
T

Thomas Weidenfeller

I guess I could use the mouse x,y coordinates to roughly
work out where the pointer is in relation to the objects on the JPanel
but is there an easier, more obvious way that I am completely unaware
of?!

This is the obvious way.

/Thomas
 
R

Roedy Green

Components themseves, not items within them. Is there any possible way
of doing this? I guess I could use the mouse x,y coordinates to roughly
work out where the pointer is in relation to the objects on the JPanel
but is t
when you put components in a Container the container's job it to look
at at mouse event and figure out which component it belongs to. It can
do this crudely by checking the bounds in turn of each component.

This is slow. You can nearly always beat this with your own code to
narrow down the focus. See
http://mindprod.com/jgloss/hangingmoss.html

..Sometimes you can do it with a simple division to get the grid square
numbers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,142
Latest member
arinsharma
Top