如何在 JfreeChart SaveAsPNG 方法中实现 SaveAs 对话框

How to implement a SaveAs Dialog in a JfreeChart SaveAsPNG method

拜托,我需要你的帮助。你能告诉我如何在下一段代码中实现 SWT SaveAs Dialog 吗?我需要用户可以选择他想保存图表的位置。谢谢!

 try {
                File file = new File("mychart.png");
                float calidad = 1;

                ChartUtilities.saveChartAsJPEG(file, calidad, chart, 800, 600);
                MessageDialog.openInformation(shell, "Save Chart", "The file has been saved");

            } catch (IOException e1) {
                e1.printStackTrace();
                MessageDialog.openInformation(shell, "Save Chart", "Error saving file. Please try again...");
            }

使用 SWT FileDialog - 类似于:

Shell shell = ... current shell

FileDialog fileDialog = new FileDialog(shell, SWT.SAVE);

fileDialog.setFilterExtensions(new String [] {"*.png", "*.*"});

fileDialog.setFilterPath(.... any default path you want ....);

String filePath = fileDialog.open();

// TODO check for null 'filePath' - user canceled the save

File file = new File(filePath);

ChartUtilities.saveChartAsPNG(file, calidad, chart, 800, 600);