Results 1 to 7 of 7
  1. #1
    TimHuey is offline Member
    Join Date
    Aug 2009
    Posts
    50
    Rep Power
    0

    Default Strange JFILECHOOSER behavior on Macs with ZIP files

    I have a multiplatform GUI app that is running on Macs, linux and Windows computers. I distribute a data file that is a zipped up txt file. In windows the jfilechooser has no problem selecting the zip file. However, on macs I can't select the file. The dialog box greys out the open option and displays the zip file as a folder. You can open the folder but the program isn't designed to work that. It needs the zip file which is extracts the files from and uses the files.

    Here is the code. Is there a property I'm not setting to allow the user to select the zip folder on a mac?
    Java Code:
     if (fileDialog == null)   // (fileDialog is an instance variable)
                  fileDialog = new JFileChooser();
               fileDialog.setDialogTitle("Select File for Reading");
               fileDialog.setSelectedFile(null);  // No file is initially selected.
             //  fileDialog.
               int option = fileDialog.showOpenDialog(mainFrame);
                   // (Using "this" as a parameter to showOpenDialog() assumes that the
                   //  readFile() method is an instance method in a GUI component class.)
               if (option != JFileChooser.APPROVE_OPTION)
                  return null;  // User canceled or clicked the dialog's close box.
               File selectedFile = fileDialog.getSelectedFile();

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Try explicitly setting the fileSelectionMode to JFileChooser.FILES_AND_DIRECTORIES

  3. #3
    TimHuey is offline Member
    Join Date
    Aug 2009
    Posts
    50
    Rep Power
    0

    Default

    You know I tried doing that with this line of code but the Netbeans said it wasn't correct:

    Java Code:
    fileDialog.FILES_AND_DIRECTORIES;
    I also tried:

    Java Code:
    fileDialog.FILES_AND_DIRECTORIES();
    no luck doing it that way either. Do I not understand how to set that flag?

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Java Code:
    fileDialog.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    P.S Refuse to write a single line of code if you don't have the API specs with you.

  5. #5
    TimHuey is offline Member
    Join Date
    Aug 2009
    Posts
    50
    Rep Power
    0

    Default

    Yea, I just tried that and I got a strange warning but not an error:

    Java Code:
    fileDialog.setFileSelectionMode(fileDialog.FILES_AND_DIRECTORIES);
    warning "Accesssing Static Field FILES_AND_DIRECTORIES"

    is that okay? oh never mind. The ide suggested changing it to class reference. That seems much better. so now my code looks like your above.

    I TOLD YOU IM REALLY NEW. MAJOR new. I really appreciate your time helping me today. We are a bunch of pilots and we don't program computers. I have a computer science minor from 20 years ago and I'm banging around trying to figure out Object oriented programming, learning java, and dumping my structured programming training.

    I would really like to take a JAVA class. I think it would save me ...AND YOU...alot of time with some of these "simple" problems.

  6. #6
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    No need to feel bad about it.
    Just make sure you have those API specs with you the same way you'd never fly without a compass.

  7. #7
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    The warning tells you that you are accessing a static field through an instance of the class. Change
    Java Code:
    fileDialog.setFileSelectionMode(fileDialog.FILES_AND_DIRECTORIES);
    to
    Java Code:
    fileDialog.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    and it will work.

    The compiler gives you this warning because static fields/methods are designed to be accessed through ClassName.STATIC_FIELD; or ClassName.staticMethod(); The compiler is just telling you that you are not using the methods as it 'expects', though it is still a valid way of using them.
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

Similar Threads

  1. htmlparser inconsistent behavior
    By sjchase in forum Advanced Java
    Replies: 0
    Last Post: 07-22-2009, 12:07 AM
  2. Strange behavior with Thread.sleep()
    By Steve11235 in forum Advanced Java
    Replies: 16
    Last Post: 05-04-2009, 06:24 AM
  3. strange refreshing behavior
    By diggitydoggz in forum New To Java
    Replies: 4
    Last Post: 12-27-2008, 05:51 PM
  4. IDE for Macs
    By jamesov89 in forum New To Java
    Replies: 1
    Last Post: 09-22-2008, 07:43 PM
  5. Object class's equals() method behavior????
    By skyineyes in forum New To Java
    Replies: 4
    Last Post: 07-20-2008, 12:58 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
  •