Reputation: 475
I realized that the chartMouseClicked method gets called only when the user left-clicks on a chart.MousePressed() and mouseReleased() methods are called When when the user right-clicks on a chart. But I need something more. I need them together.I need to find if an user right clicks on XYItemEntity.Then I will show new pop up menu item. If user select menu item, I will pass information from XYITEM. If it is not XYItemEntity, I will not update Popupmenu of chart. That is how can I check XYITEM entity on chartMouseClicked.
panel.addChartMouseListener(new ChartMouseListener() {
public void chartMouseClicked(final ChartMouseEvent event) {
/** If Time Instance point is clicked */
if (event.getEntity() instanceof XYItemEntity) {
}}
Upvotes: 1
Views: 305
Reputation: 475
I have managed to find a solution combining chartMouseMoved and mouseReleased methods.
public void chartMouseMoved(final ChartMouseEvent event) {
if (event.getEntity() instanceof XYItemEntity) {
panel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
clickedSimulationItem = (XYItemEntity) event.getEntity();
} else if (event.getEntity() instanceof PlotEntity) {
handleMouseMoveOnPlot(event);
} else {
panel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
clickedSimulationItem = null;
}
}
private void addMouseListener() {
panel.addMouseListener(new MouseListener() {
@Override
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) {
if (clickedSimulationItem != null) {
panel.getPopupMenu().add(new JMenuItem("denem"));
/** update pop up */
}
}
}
}
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
});
}
Upvotes: 2