Reputation: 7855
I'm just using the method setSize
of the ChartPanel. For some reason, it fails to work. Here's the code:
mostSoldPanel = new JPanel();
chartTabbedPane.addTab("Mais vendidos", null, mostSoldPanel, null);
mostSoldChart = ChartFactory.createBarChart("Mais vendidos", "Produtos", "Quantidade", createDataset(),
PlotOrientation.VERTICAL, true, true, false);
ChartPanel chartPanel = new ChartPanel(mostSoldChart);
mostSoldPanel.add(chartPanel);
chartPanel.setSize(mostSoldPanel.getSize());
Here's the visual result:
Upvotes: 1
Views: 258
Reputation: 347332
The likely cause is the fact that JPanel
by default uses a FlowLayout
, which is allowing the child components to use their own preferredSize
to when been laid out.
Consider changing mostSoldPanel = new JPanel();
to mostSoldPanel = new JPanel(new BorderLayout());
and get rid of the get/setSize
calls
Upvotes: 4