Adding popup menu items to JChart2D's ChartPanel
Is it possible to add menu items to JChart2D's ChartPanel pop up menu, considering the class doesn't act开发者_开发技巧ually save the JPopupMenu created by the LayoutFactory?
I found a solution, not sure if it's the best:
public class MyChartpanel extends ChartPanel {
private JPopupMenu popup;
public MyChartpanel(Chart2D chart) {
super(chart);
MouseListener[] listeners = chart.getMouseListeners();
for (MouseListener listener : listeners) {
if (listener instanceof PopupListener) {
PopupListener popupListener = (PopupListener) listener;
popup = popupListener.getPopup();
popup.add(new MyMenuItem());
}
}
}
}
I never used I think that JChart2D's ChartPanel, but JChart2D Features told something about JPopupMenu , setComponentPopupMenu, How to Use the System Tray, How to Use Separators examples here and about PopupMenuListener
精彩评论