Using the same chart in multiple JPanels

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
jahjeremy
Posts: 31
Joined: Tue Sep 25, 2012 2:49 am
antibot: No, of course not.

Using the same chart in multiple JPanels

Post by jahjeremy » Wed Mar 14, 2018 7:31 pm

Hello,

I am attempting to use the same chart object in multiple JPanels, but it doesn't seem to be working how I would expect.

Basically, I want to make a pop-up window that displays a single chart in its own JFrame when the user clicks on the smaller version of it which is displayed in the main GUI.

The code I'm trying to use is something like the following:

Code: Select all

public class ChartPopupFrame extends JFrame {
           
    public ChartPopupFrame() {
        setLayout(new BorderLayout());
        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    }
        
    // This method attempts to show an existing chart in a new pop-up window.
    public void update(ChartPanel chart) {
        this.removeAll();
        ChartPanel newPanel = new ChartPanel(chart.getChart());
        newPanel.setMinimumDrawHeight(500);
        newPanel.setMinimumDrawWidth(500);
        this.add(newPanel, BorderLayout.CENTER);
        this.setPreferredSize(new Dimension(500, 500));
        newPanel.validate();
        this.setVisible(true);
    }       
}
This approach doesn't seem to work, however, as the pop-up JFrame is blank and doesn't display the chart.

Any tips on how I might go about accomplishing this?

Locked