【发布时间】:2014-03-19 07:41:09
【问题描述】:
我知道之前有人问过这个问题(here、here 和 here),但提供的解决方案不起作用。因此,请不要将其标记为重复。我正在使用 JFreeChart 绘制折线图。然后我把这个图表放在一个 JPanel 中,然后放在一个 tabbedPane 中。 我知道直接将 JPanel 放在 JFrame 中可以调整大小,但我该怎么做呢?
public class DynamicLineAndTimeSeriesChart extends JPanel implements ActionListener {
private ArrayList<TimeSeries> Series = new ArrayList<TimeSeries>();
private ArrayList<Double> Last = new ArrayList<Double>();
private String Id1;
private Timer timer = new Timer(250, this);
public DynamicLineAndTimeSeriesChart(String id) {
Runtime runtime = Runtime.getRuntime();
int NoOfProc = runtime.availableProcessors();
for (int i = 0; i < NoOfProc; i++) {
Last.add(new Double(100.0));
Series.add(new TimeSeries("Core" + i, Millisecond.class));
}
Id1 = id;
final TimeSeriesCollection dataset = new TimeSeriesCollection();
for (int i = 0; i < NoOfProc; i++) {
dataset.addSeries(this.Series.get(i));
}
final JFreeChart chart = createChart(dataset);
timer.setInitialDelay(1000);
chart.setBackgroundPaint(Color.LIGHT_GRAY);
//Created JPanel to show graph on screen
final JPanel content = new JPanel(new GridLayout());
final ChartPanel chartPanel = new ChartPanel(chart);
content.add(chartPanel, BorderLayout.CENTER);
content.revalidate();
this.add(content);
timer.start();
}
createChart 是 JFreeChart 类型的方法。 这个类在另一个类中被调用
JPanel main = new JPanel(new BorderLayout());
main.add(demo);
jTabbedPane1.add("Core", main);
demo.setVisible(true);
框架设计是使用 NetBeans 完成的。 我已经尝试了所有解决方案,例如将布局从 BorderLayout 更改为 GridBagLayout,甚至提到了here。
【问题讨论】:
-
可能是 content.pack() ?
-
“我知道之前有人问过这个问题,但提供的解决方案不起作用。” 在哪里?请给个链接..
-
到底是什么问题?调整内容大小时是否希望 chartPanel 自动调整大小?
-
@AndrewThompson 已完成编辑。
标签: java swing netbeans jfreechart