[英]Get an access to JFrame components
How to get an access to the XYSeries
and XYPlot
placed on JFrame
? 如何访问放置在
JFrame
上的XYSeries
和XYPlot
? Of course, I can use the variable names series
and plot
, but my question refers to the functional way to access these components, ie f.getContentPane()
... This is useful when the function returns JFrame
. 当然,我可以使用变量名称
series
和plot
,但我的问题是指访问这些组件的功能方式,即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
is JComponent
which renders JFreeChart
; ChartPanel
是呈现JFreeChart
JComponent
; both XYSeries
and XYPlot
are components, these objects used by JFreeChart
. XYSeries
和XYPlot
都是组件,这些对象由JFreeChart
。 Since they're not components, you can't access them by traversing component hierarchy, you have to get them from ChartPanel
and JFreeChart
. 由于它们不是组件,因此无法通过遍历组件层次结构来访问它们,您必须从
ChartPanel
和JFreeChart
获取它们。
Find ChartPanel
in the component hierarchy, use getChart()
to get JFreeChart
object, and then get the objects you want from it, just like you do in the code above: 在组件层次结构中查找
ChartPanel
,使用getChart()
获取JFreeChart
对象,然后从中获取所需的对象,就像在上面的代码中一样:
XYPlot plot = chart.getXYPlot();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.