code: public JFrame displayChart() {
  
      // Create and set up the window.
      final JFrame frame = new JFrame(windowTitle);
  
      // Schedule a job for the event-dispatching thread:
      // creating and showing this application's GUI.
      try {
        javax.swing.SwingUtilities.invokeAndWait(
            new Runnable() {
  
              @Override
              public void run() {
  
                frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
                XChartPanel<T> chartPanel = new XChartPanel<T>(charts.get(0));
                chartPanels.add(chartPanel);
                frame.add(chartPanel);
  
                // Display the window.
                frame.pack();
                frame.setVisible(true);
              }
            });
      } catch (InterruptedException e) {
        e.printStackTrace();
      } catch (InvocationTargetException e) {
        e.printStackTrace();
      }
  
      return frame;
    }
docs: Display the chart in a Swing JFrame