code: public void save() throws IOException {
          FileChooser.SimpleFileFilter filter = FileChooser.SimpleFileFilter.getWritableImageFIlter();
          JFileChooser chooser = FileChooser.getInstance();
          chooser.setFileFilter(filter);
          chooser.setAcceptAllFileFilterUsed(false);
          chooser.setSelectedFiles(new File[0]);
          int returnVal = chooser.showSaveDialog(null);
  
          if (returnVal == JFileChooser.APPROVE_OPTION) {
              File file = chooser.getSelectedFile();
              if (!filter.accept(file)) {
                  file = new File(file.getParentFile(), file.getName() + ".png");
              }
              save(file);
          }
      }
docs: Shows a file chooser and exports the plot to the selected image file.
  @throws IOException if an error occurs during writing.