问题
In my swing application, I have set the UI Look and Feel as:
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
And it works well on Windows. Inside, the application, the user has to select files using the JFileChooser
. The JFileChooser
appearance on windows is again the native one. But not on Mac.
The screenshot of the JFileChooser Panel:
But instead, I prefer something like this: (This one is taken from upload option in gmail)
What should I change the UIManager to or anything else??
回答1:
Several alternatives include these:
java.awt.FileDialog
, illustrated here.
- A custom
ChooserUI
, shown here.
- A completely custom implementation; several variations are shown here.
回答2:
On MacOS, you can use the FileDialog which looks like what you are describing. The drawback is that it is a lot less configurable.
回答3:
The file chooser implementation for Windows, Linux and Mac is not 100% right for any OS
Unfortunately if you really want this you need to look for a replacement for JFileChooser or you need to write your own look and fee.
Java has trouble keeping up with the OS changes.
回答4:
I have experienced a lot of troubles when migrating from Java 6 to Java 8 since with my Java application I have to open some proprietary file bundles.
FileDialog still gives the better LookAndFeel, but treats the bundled files as if it were directories. A first fix to this is to set FileDialog to select directories, which still allows to navigate inside the file-bundle, but as well allows to select the bundle as a whole.
System.setProperty("apple.awt.fileDialogForDirectories", "true");
Not quite happy by the solution I tried other options, including the VAqua LookAndFeel for macOS which looked really great but sometimes didn't display me all the UI Elements (some JTree were hidden at startup, and JFileChooser did look great, but still didn't show me the Network drives in the sidebar).
Finally I found a simple property that - when set - allows to use FileDialog as it was under Java 6. Of course, if we want to select files and not directories, the line above must be deleted.
System.setProperty("apple.awt.use-file-dialog-packages", "true");
Found this one in an old example project about Dialog personalization
来源:https://stackoverflow.com/questions/13798163/jfilechooser-appearance