Search code examples
javaswingjfreechart

Add listener to Legend


I am using XYPlot class from jfreechart library. I have got two XYSeries and there are legend of them in the bottom of the ChartPanel. Now I want to process mouse click events on that legend. Is it possible to add listener to the legend? If it is not how can I get the coordinates of legend (with coordinates I can add listener to ChartPanel)?


Solution

  • As shown here, you can create your own component in which to render legend items. The example decorates each JLabel with a ColorIcon, which is also suitable for a JButton.