This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Unusal JFileChooser behaviour

Ranch Hand
Posts: 176
Mac Chrome Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
    Posts: 74696
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.
    WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
    Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
      Bookmark Topic Watch Topic
    • New Topic