I'm using JFileChooser
which don't want to close after I press close button. The problem is that after I press the close button, it opens again 3+ times, and finally closes.
My code:
javaButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setDialogTitle("Save");
int option = fileChooser.showSaveDialog(null);
if (option == JFileChooser.APPROVE_OPTION) {
String filename = fileChooser.getFileFilter().getDescription();
try {
ChartUtilities.saveChartAsPNG(new File(filename), chart, getWidth(), getHeight());
} catch (java.io.IOException exc) {
System.err.println("Error writing image to file");
}
}
if (option == JFileChooser.CANCEL_OPTION) {
System.out.println("Task canceled!");
//tried: fileChooser.setVisible(false); // >> same problem
}
}
});
Any advice?