Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: help with parameters in FileChooser

  1. #1
    Junior Member
    Join Date
    Apr 2019
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default help with parameters in FileChooser

    Hi everyone! I am learning java programming in my spare time and I'm having trouble with some parameters in showSaveDialog. I can´t get the save dialog to appear. Any suggestions will be helpful. Thanks in advance.

    import java.io.*;
    import javafx.stage.FileChooser;
    import javax.swing.JOptionPane;
     
    public class main extends javax.swing.JFrame {
     
        private void saveToFile(){
            try{
                FileWriter writer=new FileWriter("save.nfo",false);
                writer.write(id.getText());
                writer.write(System.getProperty("line.separator"));
                writer.write(name.getText());
                writer.write(System.getProperty("line.separator"));
                writer.write(dep.getText());
                writer.write(System.getProperty("line.separator"));
                writer.close();
     
     
                JOptionPane.showMessageDialog(rootPane,"Success");
     
            }catch(Exception e){
                JOptionPane.showMessageDialog(rootPane,"Error");
            }
        }
     
        private void saveActionPerformed(java.awt.event.ActionEvent evt) {                                     
     
            //Set extension filter for text files.
            FileChooser fileChooser=new FileChooser();
            FileChooser.ExtensionFilter extFilter=new FileChooser.ExtensionFilter("Only TXT files (*.txt)", "*.txt");
            fileChooser.getExtensionFilters().add(extFilter);
     
     
     
            //Show save file dialog
            File file=fileChooser.showSaveDialog();//Don't know what parameter to use to make the dialog appear. No errors with 'null' but not helpful. 
     
            if (file != null) {
                saveToFile();
            }
     
        }                                    
     
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,407
    Thanks
    53
    Thanked 2,399 Times in 2,352 Posts

    Default Re: help with parameters in FileChooser

    FileChooser belongs with the javafx classes. Try using the JFileChooser class. It is part of the swing classes.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2019
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: help with parameters in FileChooser

    Thanks. Have some errors in the extension filters but I'll look it up.

Similar Threads

  1. More parameters vs more methods
    By Cornix in forum Java Theory & Questions
    Replies: 1
    Last Post: January 23rd, 2014, 03:47 PM
  2. FileChooser (mp3/wav) and drop it to textArea
    By karlburgos in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 6th, 2014, 12:29 AM
  3. Interface parameters?
    By markjava in forum Java Theory & Questions
    Replies: 3
    Last Post: November 18th, 2012, 08:21 AM
  4. [SOLVED] Why re-name these method parameters?
    By pict3000 in forum Object Oriented Programming
    Replies: 6
    Last Post: August 9th, 2012, 06:07 AM
  5. Help using parameters
    By white97 in forum Object Oriented Programming
    Replies: 6
    Last Post: August 9th, 2011, 07:28 PM