I have a save dialog box that seems to work except for a couple issues:
1) when the save dialog first opens I want a default filename "testing.txt" to appear in the filename field.
How do I make this happen?
(currently trying "setSelectedFile(new File("FileName"));", but no luck yet)
2)How can I make the file ALWAYS save as .txt by default?
any suggestions are greatly appreciated.
below is the code for my save button:
Thanks.
YaK
1) when the save dialog first opens I want a default filename "testing.txt" to appear in the filename field.
How do I make this happen?
(currently trying "setSelectedFile(new File("FileName"));", but no luck yet)
2)How can I make the file ALWAYS save as .txt by default?
any suggestions are greatly appreciated.
below is the code for my save button:
Code:
String messageCont = outTextArea.getText(); /*create file chooser*/ final JFileChooser fc = new JFileChooser(); /*attache the file chooser to the Frame and detect OK or Cancel*/ int returnVal = fc.showSaveDialog(HanoiFrame.this); //fc.setSelectedFile(); File file = fc.getSelectedFile(); //File file = fc.setSelectedFile(new File("testing.txt")); if (returnVal == JFileChooser.APPROVE_OPTION) { try { /*if OK write the file*/ BufferedWriter output = new BufferedWriter(new FileWriter(file.getPath() + file.getName())); output.write(messageCont); output.close(); } catch (IOException ex) { ex.printStackTrace(); } } else { /*cancel*/ return; }
YaK
Comment