Reputation: 13
I have a JFreeChart
with 2 subplots (XYPlot).
I have XYImageAnnotation
s that I want to become buttons, but I can't find a way to listen mouse click on any annotation.
Do you know any way to do this?
Upvotes: 1
Views: 615
Reputation: 7136
I have no idea how to listen [for] click from annotations
In your ChartMouseListener
, you'll get a ChartMouseEvent
. Use it to get the ChartEntity
that's a XYAnnotationEntity
.
chartPanel.addChartMouseListener(new ChartMouseListener() {
@Override
public void chartMouseClicked(ChartMouseEvent cme) {
ChartEntity ce = cme.getEntity();
if (ce instanceof XYAnnotationEntity) {
// handle the click
}
}
}
Otherwise, look for the XYItemEntity
to which you added the annotation.
Upvotes: 1