0

I am writing a simple filechooser and in it I have the code:

JFileChooser fc = new JFileChooser();
int result = fc.showOpenDialog(null);  

When I run this under Windows (7) I get a chooser with a text field in which I can enter a file name (Note the File: [text box] at the bottom):

Note the File: [text box] at the bottom

But when I run the same code on a Mac (OSX Mavericks) I get a window with no option to enter a filename:

No way to type in a file name

I found that I can get around this by using fc.showDialog instead, (or probably showSaveDialog with customized text, though I haven't tried that) but I'm wondering why there would be this difference in the platforms. I work at home under Windows then teach a class on a Mac. It's embarrassing to have my example code not work correctly!

TIA for any insights or advice.

Micho
  • 3,929
  • 13
  • 37
  • 40
BAleiHi
  • 11
  • 2
  • Yep, that's how it works - there are different expectations between Mac and Windows ... as annoying as it is. One possible solution is to use the AWT file dialog on Mac, but I can't say if that's any better – MadProgrammer Mar 27 '18 at 03:01
  • This is the kind of Open file dialog we Mac users are used to see (or at leas was used to see since it's a bit old), if you try to change it you will only create confusion among the users that are used to a specific behaviour. I fail to see how your code will not behave correctly because of this. – Joakim Danielson Mar 27 '18 at 05:29
  • Yes, it certainly occurred to me that there may not be a reason to type in a name when opening a file since, presumably the file exists. But it's not that my code does not behave "correctly", just that the implementations are different on the two platforms. And I see why dedicated Mac users might want different functionality than dedicated Windows users, each wanting to match what they're used to. I guess this really gets to the ultimate futility of trying to write platform independent code. – BAleiHi Mar 28 '18 at 05:38

0 Answers0