簡體   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