Usually it defaults to the metal look and feel in my experience, not the
"System" look and feel.
Well, I'm not that familiar with the different "looks" and "feels", but
while the program defaults to a decidedly non-XP look on Windows XP, on
the Mac the look-and-feel is very much Mac-like. I'd just assumed the
Windows default was supposed to be Vista-like, but I don't really have
enough experience with Vista to know. Maybe it's the "metal"
look-and-feel after all and I just didn't recognize it as such.
It's not surprising that Apple would choose to make their own
look-and-feel the default though.
The funny thing is, though...
Does it look anything like the Mac OS file dialog? What happens when
you run your program on Windows?
No, it looks nothing like the Mac OS file dialog. On Windows,
JFileChooser looks (mostly) the same as Mac if I don't include the code
you suggested, but that version doesn't blow away the filename when you
change directories (i.e. it works fine). If I do include the
initialization code you suggested, then the Swing JFileChooser looks the
same as the AWT FileDialog, which in turn looks the same as the Windows
built-in file chooser dialog.
On the Mac, AWT always looks like the OS dialog, Swing always doesn't,
regardless of whether I include the code you suggested. Interestingly,
the Swing dialog _does_ look a lot like the Windows one, other than the
fact that the various control elements within the dialog still have the
Mac look. But it doesn't behave as well, and it doesn't change depending
on whether the look-and-feel is explicitly set at startup or not.
Which is odd, actually. Given the Windows behavior, it would make more
sense for the "metal" version of the dialog to only show up if I somehow
managed to get the rest of the UI in the "metal" look-and-feel. I assume
there's an explicit class that I could use to do that (the docs appear to
suggest javax.swing.plaf.metal.MetalLookAndFeel). Given that the rest of
the application appears to default to the system look-and-feel on the Mac,
it seems odd that the "metal" dialog is what shows up with JFileChooser.
I am starting (hah
) to think that maybe these issues are all pretty
much related to the same issue: Apple just didn't implement the Java
run-time carefully and failed to be consistent with how the run-time works
on other systems.
EDT = Event Dispatch Thread (eg, using EventQueue.invokeLater())
Everything that interacts with swing components should do so from that
thread.
Never heard of it. I wonder if that means I'm doing something wrong.
I do all of my initialization, including creating the UI, from the thread
that calls the main() method (i.e. all of the initialization, other than
class member initializers, is done in calls from that method). After
that, everything happens in whatever thread handles the UI (i.e. the
program has no additional threads...it only ever does something as a
reaction to some UI event).
I assume that the stuff that happens in the thread that handles the UI is
fine, but is there something wrong with where I'm initializing the UI?
Should I somehow be getting my initialization code to be running on a
different thread than the one that calls my main() method?
Thanks,
Pete