How to “Open” and “Save” using java

You want to use a JFileChooser object. It will open and be modal, and block in the thread that opened it until you choose a file. Open: JFileChooser fileChooser = new JFileChooser(); if (fileChooser.showOpenDialog(modalToComponent) == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); // load from file } Save: JFileChooser fileChooser = new JFileChooser(); if (fileChooser.showSaveDialog(modalToComponent) == … Read more

How do I set a suggested file name using JFileChooser.showSaveDialog(…)?

If I understand you correctly, you need to use the setSelectedFile method. JFileChooser jFileChooser = new JFileChooser(); jFileChooser.setSelectedFile(new File(“fileToSave.txt”)); jFileChooser.showSaveDialog(parent); The file doesn’t need to exist. If you pass a File with an absolute path, JFileChooser will try to position itself in that directory (if it exists).

JOptionPane YES/No Options Confirm Dialog Box Issue

You need to look at the return value of the call to showConfirmDialog. I.E.: int dialogResult = JOptionPane.showConfirmDialog (null, “Would You Like to Save your Previous Note First?”,”Warning”,dialogButton); if(dialogResult == JOptionPane.YES_OPTION){ // Saving code here } You were testing against dialogButton, which you were using to set the buttons that should be displayed by the … Read more