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);
}
}
Any tips on how I might go about accomplishing this?