• 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 ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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?

    Thank-you

    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?
     
    Marshal
    Posts: 79153
    377
    • 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.
     
    This tiny ad is wafer thin:
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic