Im using netbeans gui editor and im trying to add a Jfreechart that is itself in a internal frame, and this internal frame I am wanting to add it to a panel, as you can see in this image:

http://www.flickr.com/photos/63259070@N06/6370734167/

The internal frame doesn't even show up on the panel "Estadisticas" when I run it, I think its harder because im not doing the gui by code but it shouldn't be that hard, If anyone could help me add this properly I would greatly appreciate it, here is the code that I have been trying out:

private void display() {
       DefaultPieDataset pieDataset = new DefaultPieDataset();
    pieDataset.setValue("One", new Integer(10));
    pieDataset.setValue("Two", new Integer(20));
    pieDataset.setValue("Three", new Integer(30));
    pieDataset.setValue("Four", new Integer(10));
    pieDataset.setValue("Five", new Integer(20));
    pieDataset.setValue("Six", new Integer(10));
    JFreeChart chart = ChartFactory.createPieChart3D(
        "3D Pie Chart", pieDataset, true, true, true);
    ChartPanel cp = new ChartPanel(chart);
     //  JInternalFrame jif = new JInternalFrame(
     //   "Chart", true, true, true, true);
    this.ji.add(cp); //ji is the name of the internal frame
    this.ji.pack();
    this.ji.setVisible(true);
    this.ji.setSize(100, 100);

    JDesktopPane dtp = new JDesktopPane();
    dtp.add(ji);
    this.jpEstadisticas.add(dtp);   //jpEstadisticas the name of the main "Estadisticas"panel

}

Dani AI

Generated

Brief summary and the simplest fix: don’t create a new JDesktopPane and don’t rely on absolute sizes. If the chart is already wrapped in a ChartPanel (as in the original post), add that ChartPanel directly into a placeholder JPanel on the NetBeans form (or into the internal frame’s content pane) using a BorderLayout, then revalidate/repaint. In the original code created a new JDesktopPane and set the internal frame to 100×100, which commonly makes the frame invisible or clipped by the form’s GroupLayout. ’s crosspost confirms this is the same problem seen on StackOverflow.

Example — add an existing ChartPanel instance to the panel that was placed on the form (do this after initComponents()):

/* assuming a ChartPanel instance named chartPanel already exists */
jpEstadisticas.setLayout(new BorderLayout());   // set via GUI editor or in code
jpEstadisticas.removeAll();
jpEstadisticas.add(chartPanel, BorderLayout.CENTER);
jpEstadisticas.revalidate();
jpEstadisticas.repaint();

If an internal frame (ji) must be used and it was created on the form, put the ChartPanel into the internal frame’s content pane and add that internal frame to the desktop pane already placed on the form — do NOT create a new JDesktopPane at runtime:

ji.getContentPane().setLayout(new BorderLayout());
ji.getContentPane().removeAll();
ji.getContentPane().add(chartPanel, BorderLayout.CENTER);
ji.pack();
ji.setVisible(true);

/* add ji to the desktopPane that exists in the form (desktopPaneOnForm) */
desktopPaneOnForm.add(ji);
desktopPaneOnForm.revalidate();
desktopPaneOnForm.repaint();

Extra tips: run UI updates on the Event Dispatch Thread (SwingUtilities.invokeLater), prefer setPreferredSize()/pack() over fixed setSize(), and use temporary background colors or borders to confirm component bounds while debugging. Avoid editing NetBeans’ guarded initComponents() — make these additions after initComponents() runs.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.