how do I make jfilechooser only accept .txt
You need to add a filter: JFileChooser jf = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter(“TEXT FILES”, “txt”, “text”); jf.setFileFilter(filter);
You need to add a filter: JFileChooser jf = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter(“TEXT FILES”, “txt”, “text”); jf.setFileFilter(filter);
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
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).
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