Mouse Events

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Ted Hill
Posts: 54
Joined: Mon Jun 12, 2006 7:39 pm

Mouse Events

Post by Ted Hill » Tue Jul 11, 2006 5:17 pm

The ChartPanel class has an addChartMouseListener() method which will be called on mouseMoved and mouseClicked.

What is the best way to get called for other mouse events. In particular I want mousePressed, mouseDragged, mouseReleased.

Should I subclass ChartPanel which handles these other mouse events?

Or is there a better way to do this?

Is there a demo that shows how to get the other mouse events?

Thanks,
Ted Hill

gribas
Posts: 32
Joined: Thu Jan 26, 2006 5:34 pm

Post by gribas » Tue Jul 11, 2006 6:01 pm

If you want just the mouse events, call addMouseListener() , after all, ChartPanel is a Panel.

If you want Chart events (like what chart entity is below a mousePressed coordinate) you'll have to subclass or modify ChartPanel itself. You could also create your own method to find chart entities given a screen coordinate.

regards,
Gustavo

develop
Posts: 296
Joined: Wed Mar 23, 2005 10:01 pm

Post by develop » Tue Jul 11, 2006 9:58 pm

i have implemented all mouse event as i needed to do that , i subclassed ChartPanel and override all mouse events and i also called super for each method and its working fine.

Thanks

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Mouse Events

Post by david.gilbert » Wed Jul 12, 2006 4:53 pm

Ted Hill wrote:What is the best way to get called for other mouse events. In particular I want mousePressed, mouseDragged, mouseReleased.
I haven't written any code that handles these other events. Eventually I'd like to give it a try, but since I haven't done so yet, I can't really offer any advice. It would be great if you could post some code if you get something working...
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

develop
Posts: 296
Joined: Wed Mar 23, 2005 10:01 pm

Post by develop » Wed Jul 12, 2006 5:01 pm

all i do is following

CustomChartPanel extends ChartPanel implements MouseMotionListener{
...}

then i implement all mouse events.

the functioanlity that i needed is this.
user clicks on button then he starts dragging mouse and draw line on chart and when he released the mouse, that line should be drawn on chart.

for this i grab the mouse point when user presses mouse and to draw line i used XYLIneAnnotation.

I can make sample program if any one wants...

Thanks

the_schmitz
Posts: 13
Joined: Thu May 18, 2006 6:01 pm
Location: Washington DC

Yes Please!

Post by the_schmitz » Sun Jul 23, 2006 3:07 pm

Hi develop,
I'd like to see a sample program. I have a similar need for something like this, with a twist.

I have a client that wants to be able to click on a datapoint and then have a little window popup on the graph with information regarding the datapoint. Kind of like a tooltip, but a bit more advanced. They want the information to stay on the graph, so when they print it, or save it, they'll still see it. They also want to be able to move the window around, and dismiss it.

So, a sample program with the MouseMotionListener stuff, would be a great starting point for me.
Thanks in advance!

Locked