I know this question has been asked earlier (here ,here and here), but the offered solutions are not working. Hence, please don't mark it as duplicate. I am drawing a line chart using the JFreeChart. Then I put this chart inside a JPanel which is then put in a tabbedPane. I know directly putting the JPanel in a JFrame makes it resizable but how can I do it this way?
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 is a method of type JFreeChart. This class is called in another class
JPanel main = new JPanel(new BorderLayout());
main.add(demo);
jTabbedPane1.add("Core", main);
demo.setVisible(true);
The frame designing was done using NetBeans. I have tried all the solution like changing the layouts from BorderLayout to GridBagLayout and even the one mentioned here.