开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜