enig
enig

Reputation: 13

JFreeChart XYPlot XYImageAnnotation mouse click listener

I have a JFreeChart with 2 subplots (XYPlot).

I have XYImageAnnotations 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

Answers (1)

Catalina Island
Catalina Island

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

Related Questions