是否可以将菜单项添加到JChart2D的ChartPanel弹出菜单中,考虑到该类实际上没有保存由LayoutFactory创建的JPopupMenu?
答案 0 :(得分:2)
我找到了一个解决方案,不确定它是否是最好的:
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());
}
}
}
}
答案 1 :(得分:1)
我从未使用过我认为JChart2D的ChartPanel,但是JChart2D Features告诉了JPopupMenu,setComponentPopupMenu,How to Use the System Tray,How to Use Separators示例here和约PopupMenuListener