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:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.