Java JFreeChart Not fully displaying chart in JPanel

I have been experimenting with JFreeChart for an upcoming project and looking at the tutorials they seem to be pretty straight forward. I created a simple little program that asks for some data and display a 3D pie chart. It works but when displaying the chart in the panel it only partially shows the chart. If you click inside the panel it will then grow to the size of the display panel. I've tried setting various setPreferredSize() at different places but none of it seems to work. What am I missing?

import java.awt.Dimension;
import java.awt.EventQueue;
import javax.swing.JFrame;
import java.awt.Rectangle;
import javax.swing.JPanel;
import javax.swing.border.EtchedBorder;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JLabel;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.JButton;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.util.Rotation;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import net.miginfocom.swing.MigLayout;

public class mWindow extends JFrame{

private JPanel pnlDisplay;
private JPanel panel;
private JLabel label_1;
private JLabel label_2;
private JSpinner spinner;
private JButton button;

 *  Window Constructor
private mWindow(){
    setBounds(new Rectangle(0, 0, 600, 500));
    getContentPane().setLayout(new MigLayout("", "[200px:200.00][564px,grow]", "[120px:120.00][308px,grow]"));

    panel = new JPanel();
    panel.setBorder(new EtchedBorder(EtchedBorder.RAISED, null, null));
    getContentPane().add(panel, "cell 0 0,grow");

    label_1 = new JLabel("Control Panel");
    label_1.setBounds(10, 10, 100, 20);

    label_2 = new JLabel("Number of Values");
    label_2.setBounds(10, 40, 100, 20);

    spinner = new JSpinner();
    spinner.setBounds(120, 40, 40, 20);

    button = new JButton("Create Pie Chart");
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
    button.setBounds(10, 70, 150, 40);

    pnlDisplay = new JPanel();
    pnlDisplay.setBorder(new EtchedBorder(EtchedBorder.RAISED, null, null));
    getContentPane().add(pnlDisplay, "cell 0 1 2 1,grow");


private void createPieChart(){

    //  create the data set
    //  create the chart
    //  put chart in a panel
    //  set default configuration for panel
    //  add panel to our displayPanel

    int numVal = (int) spinner.getValue();
    JTextField label = new JTextField();
    JTextField value = new JTextField();        
    DefaultPieDataset dds = new DefaultPieDataset();

    final JComponent[] fieldInput = new JComponent[]{
            new JLabel("Label Name"), label,
            new JLabel("Value"), value

    for(int index = 0; index < numVal; index++){
        // Display a dialog asking for the Information Needed to add a job
        int n = JOptionPane.showConfirmDialog(
                "Create Data Set " + (index+1), 

        if(n < 0){
            JOptionPane.showMessageDialog(this, "No Data Set has been created", 
                    "Data Set Add Canceled ", JOptionPane.ERROR_MESSAGE);

        String Label = label.getText();
        int Value = Integer.parseInt(value.getText());
        dds.setValue(Label, Value);

    // Data set ready ~ create the chart
    JFreeChart chart = ChartFactory.createPieChart3D("Our Pie Chart",          // chart title
            dds,                // data set
            true,               // include legend
            true,               // enable tool tips
            false);             // use urls

    PiePlot3D plot = (PiePlot3D) chart.getPlot();
    plot.setStartAngle(290);                        // angel of first data set
    plot.setDirection(Rotation.CLOCKWISE);          // rotation of chart
    plot.setForegroundAlpha(0.2f);                  // set alpha transparency

    // create a panel to track chart changes and set it's default size
    final ChartPanel chartPanel = new ChartPanel(chart);


    // add our chart to our display panel


 *  Initializes and Show the GUI
private static void InitalizeAndShowGUI(){
    mWindow mainWindow = new mWindow();
    mainWindow.setTitle("Chart Demo v0.1");
    Dimension windowSize = new Dimension(600,700);
    mainWindow.setLocation(100, 100);

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
            } catch (Exception e) {


After adding the new chart component, you need to repaint it to make it appear fully:


Need Your Help

LibGdx - How to set layers for the Sprites

java libgdx sprite render layer

Just for the start I'm new to the Java programming and especially to the LibGdx and I would like to ask community, because I have found some problem with Sprites, that I couldn't dealt with.

Marionette `close()` or `empty()`

backbone.js marionette backbone-views

In my app I am adding views to content region and header,footer. before I add a view, I am trying to find if there is a controller exist. if so i am trying to close those regions before I add another

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.