Results 1 to 3 of 3
  1. #1
    innovo is offline Member
    Join Date
    Jul 2015
    Posts
    84
    Rep Power
    0

    Default correct syntax using filechooser? netbeans

    Hello all, I was just curious how I could go about using the file chooser appropriately. I was going to set an "if" statement to check if a user selected a file, and if they did, then do whatever with the file. I am stuck in the if-statement unfortunately.

    According to netbeans this is syntactically incorrect.
    Java Code:
    if(fileSelect.APPROVE_OPTION ==true) {
           System.out.println("You chose to open this file: " +
            //    chooser.getSelectedFile().getName());
        }
    I'm not quite sure why exactly. I keep getting "incompatible types int and boolean" despite not using an integer and using "==" which means to not do boolean. I'm sure there's something I'm not getting here but could someone tell me what's wrong here?


    the whole code from that section
    Java Code:
    mainWindow() throws FileNotFoundException, IOException  {
          //  int line =1;
            initComponents();
            templateFile = openFile();
            jLabel11.setForeground(Color.green);
            jLabel11.setText("No Additional Instructions");
            
            if(templateFile == null){ // if template file has nothing in it
                System.exit(0);  // quit application
            }
            File file = fileSelect.getSelectedFile();  //
            CSVReader reader = new CSVReader(new FileReader(file));
            String [] nextLine;
         //   int returnVal = chooser.showOpenDialog(parent);
        if(fileSelect.APPROVE_OPTION ==true) {
           System.out.println("You chose to open this file: " +
             fileSelect.getSelectedFile().getName());
        }
        
            while ((nextLine = reader.readNext()) != null) { //while the row isn't blank
            // nextLine[] is an array of values from the line
            System.out.println(nextLine[0] + nextLine[1] + "etc...");
            if(nextLine[0]!=null){  // if there are comments 
                jLabel11.setForeground(Color.red); //turn jlabel red
                jLabel11.setText(nextLine[20]);  // show the instructions
            }
         }
    Last edited by innovo; 09-04-2015 at 12:30 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: correct syntax using filechooser? netbeans

    "incompatible types int and boolean"
    In the expression: fileSelect.APPROVE_OPTION ==true
    fileSelect.APPROVE_OPTION is an int (read the API to see its definition)
    true is a boolean
    The compiler does not know how to compare them.

    APPROVE_OPTION is one of the int values that can be returned by a show... method.

    Why is line 14 commented out? That is the line that needs to be used!
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: correct syntax using filechooser? netbeans

    Did you read the API documentation for that class? I bet you haven't: the showXXX( ... ) method return an (int) indication of what the user pressed to quit that dialog. I won't tell you how to do it; read the API documentation and please don't make wild guesses ...

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. Replies: 0
    Last Post: 04-22-2014, 10:41 PM
  2. FileChooser
    By Unsub in forum New To Java
    Replies: 7
    Last Post: 03-10-2010, 03:54 AM
  3. Syntax correct?
    By dbashby in forum New To Java
    Replies: 5
    Last Post: 09-22-2009, 06:44 AM
  4. Filechooser
    By Joe2003 in forum New To Java
    Replies: 5
    Last Post: 02-26-2009, 07:51 AM
  5. FileChooser UI
    By heartysnowy in forum New To Java
    Replies: 5
    Last Post: 11-27-2008, 03:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •