This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Unusal JFileChooser behaviour Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Unusal JFileChooser behaviour" Watch "Unusal JFileChooser behaviour" New topic

Unusal JFileChooser behaviour

Olivier Legat
Ranch Hand

Joined: Nov 17, 2007
Posts: 176

Howdy folks,

So I have this primitive code here that worked fine on Windows the last time I ran it:

But now when I run it on Mac something odd happens:

  • If I break this code before the method I notice that chooser.getFileFilter() returns null This is madness! I just set a few lines ago.
  • Furthermore the filter don't do their job at all... they all show everything.
  • And the "All-Files" filter is displayed.

  • How? Why is the behavior of this method completely different on Window and Mac?


    P.S. I'm developing on Windows using Java 7, but it seems like OSX lion only supports Java 6 (say Apple, correct me if I'm wrong).. Could this be what causes the problem?

    Campbell Ritchie

    Joined: Oct 13, 2005
    Posts: 37865
    You can try entering
    java -version
    javac -version
    ... at the command line on your Mac.

    Don’t know about the file chooser, but I can give a few hints:

    If you look at methods like this one, it says “since 1.3”, but I can’t see similar tags about the methods you are using, so that is probably not the explanation. I would have thought that using the wrong version would produce Exceptions like this (unlikely), or (more likely) this, or this.
    Put a few println calls in that method, and display the state of the filter just before you return it. Confirm you are actually calling that method. Similarly just before you use the filter the first time. Confirm there are no changes to its state. Also print its hash code; since the hashCode() method is “inherited from Object“, getting two different hash codes will make you suspicious you have not got the same reference.
    subject: Unusal JFileChooser behaviour
    Similar Threads
    excluding files using FileFilter
    Properly shutting off logging
    Problem while disposing JFileChooser
    JFileChoosers and file extensions
    JFileChooser modification