0

Is it possible set the text of the "Save As: " line in a FileDialog? I would like to set it so that when the dialog is created, there is a suggested name for the file instead of just blank space (as shown below). Thanks.

enter image description here

connorp
  • 254
  • 2
  • 12

1 Answers1

1

you can do that like .

 JFileChooser chooser = new JFileChooser();
 if (targetFile != null) {
 chooser.setSelectedFile(targetFile);
 } else {
 chooser.setSelectedFile(newFile("default.xyz"));
 }
 int option = chooser.showSaveDialog(null);
 if (option == JFileChooser.APPROVE_OPTION) {
 targetFile = chooser.getSelectedFile();
 }

That pops up a Save file dialog in the working directory and dispalys default.xyz

Anand Dwivedi
  • 1,452
  • 13
  • 23