Reputation: 509
I need to add two chartPanels in a same JPanel.
I did this for a single chartPanel, and it worked:
JPanel content = new JPanel(new BorderLayout());
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
content.add(chartPanel);
But I tried to add the second chartPanel doing this:
JPanel content = new JPanel(new GridLayout(0,2));
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
content.add(chartPanel);
final ChartPanel chartPanel2 = new ChartPanel(chart);
chartPanel2.setPreferredSize(new java.awt.Dimension(500, 270));
content.add(chartPanel2);
But when I do this, both graphs are displaying in a wrong way, like only a line or something, why this is happening?
Upvotes: 1
Views: 1710
Reputation: 205885
Use the ChartPanel
constructor that lets you specify the preferred size, as shown here. Alternatively, override getPreferredSize()
, as shown here.
Upvotes: 2