开发者

Adding popup menu items to JChart2D's ChartPanel

开发者 https://www.devze.com 2023-03-10 23:02 出处:网络
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

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

精彩评论

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