繁体   English   中英

获取对JFrame组件的访问权限

[英]Get an access to JFrame components

如何访问放置在JFrame上的XYSeriesXYPlot 当然,我可以使用变量名称seriesplot ,但我的问题是指访问这些组件的功能方式,即f.getContentPane() ...当函数返回JFrame时这很有用。

JFrame f = new JFrame(title);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout(new BorderLayout(0, 5));
XYSeries series = new XYSeries("");
XYDataset data = createDataset(series,0,indf,oldpop);
JFreeChart chart = ChartFactory.createScatterPlot(title, xtitle, ytitle, data, PlotOrientation.VERTICAL, false, true, false);
XYPlot plot = chart.getXYPlot();
XYLineAndShapeRenderer renderer =
                (XYLineAndShapeRenderer) plot.getRenderer();
renderer.setBaseShapesVisible(true);          plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
ChartPanel chartPanel = new ChartPanel(chart);
f.add(chartPanel, BorderLayout.CENTER);
chartPanel.setMouseWheelEnabled(true);
chartPanel.setHorizontalAxisTrace(true);
chartPanel.setVerticalAxisTrace(true);
JPanel panel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
f.add(panel, BorderLayout.SOUTH);

ChartPanel是呈现JFreeChart JComponent ; XYSeriesXYPlot都是组件,这些对象由JFreeChart 由于它们不是组件,因此无法通过遍历组件层次结构来访问它们,您必须从ChartPanelJFreeChart获取它们。

在组件层次结构中查找ChartPanel ,使用getChart()获取JFreeChart对象,然后从中获取所需的对象,就像在上面的代码中一样:

XYPlot plot = chart.getXYPlot();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM