禁用JFreeChart的右键菜单

时间:2017-09-03 15:06:02

标签: jfreechart

我想禁用JFreeChart的右键菜单。

我尝试了chartPanel.setPopupMenu(null),但它没有用。

Right Click Menu

1 个答案:

答案 0 :(得分:0)

以下示例使用“panel.setPopupMenu(null)”创建一个简单的XYPlot,禁用弹出菜单。 ` 公共类DisableChartPopupMenu扩展了ApplicationFrame {

public DisableChartPopupMenu(String title) {
    super(title);
}

public static void main(final String[] args) {
    (new DisableChartPopupMenu("example")).createChartNoPopupMenu();
}

public void createChartNoPopupMenu(){
    final XYSeries series1 = new XYSeries("Series 1");
    series1.add(10.0, 12353.3);
    series1.add(20.0, 13734.4);
    series1.add(30.0, 14525.3);
    series1.add(40.0, 13984.3);
    final XYSeriesCollection collection = new XYSeriesCollection();
    collection.addSeries(series1);
    final XYItemRenderer renderer1 = new StandardXYItemRenderer();
    final NumberAxis rangeAxis1 = new NumberAxis("Range 1");
    final XYPlot subplot1 = new XYPlot( collection, null, rangeAxis1, renderer1);
    final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Domain"));
    plot.add(subplot1, 1);
    JFreeChart chart = new JFreeChart(" Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    final ChartPanel panel = new ChartPanel(chart, true, true, true, false, true);
    panel.setPopupMenu( null );
    setContentPane(panel); pack(); setVisible(true);
}

} `