Search code examples
jfreechartmouseclick-event

JFreeChart: ChartMouseClicked not working


I'm using the JFreeChart library and created a chartPanel with chartMouseListener. What is strange is that the chartPanel did respond to chartMouseMove event but the chartMouseClicked is never trigger even though I've clicked very hard.

Any one can throw some light upon this issue? Really appreciated!


Solution

  • With out seeing your, code it is quite hard to guess what it going on. You must implement ChartMouseListener somewhere and then add it to the chart panel.

    public class MyChart implements ChartMouseListener 
    

    later

    chartPanel.addChartMouseListener(this)
    

    then override the the chartMouseClicked method

    @Override
    public void chartMouseClicked(ChartMouseEvent e){
        if(e.getTrigger().getButton() ==  MouseEvent.BUTTON1) {
            //do something interesting
        }
    }