-
-
Notifications
You must be signed in to change notification settings - Fork 314
System File Chooser #988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
System File Chooser #988
Conversation
…NSSavePanel on macOS
…and IFileSaveDialog on Windows
- use `optionsSet` and `optionsClear` (as on Windows) - delete local reference after getting Java array item - added "or null" to javadoc
…ent for `JFileChooser`
- made C methods `static` (similar to `private` in Java) to avoid that they are added (exported) to shared library symbol table - macOS and Linux: added `-fvisibility=hidden` to compiler options to mark C methods hidden by default
…alog on Windows and Linux (not yet used in `SystemFileChooser`
…alog on macOS (not yet used in `SystemFileChooser`
…s on Windows (not yet used in `SystemFileChooser`
…is shown Testing: reduced duplicate code
- always use some window as owner (similar to `JFileChooser`) - Linux: use "Select" for approve button in directory selection
…been built in artefacts
|
java-2025-06-08-110041 copy.txt |
And it does not crash if you press the "Cancel" button? Is this correct? Many thanks for the additional logs. I'll have a look 👍 |
|
Have updated macOS to 15.5 and can now reproduce the issue. Working on a fix... |
- disabled cross-compile for arm64 architecture on x86_64 Linux - use `apt-get` instead of `apt` - use long command line options for `codesign`
- fixed build issue on ubuntu arm64 - disabled signing on macOS (because it no longer works and I have no idea how to fix it)
2146159 to
5c2d8ba
Compare
|
The crash on macOS 15.x is now fixed in latest |
|
There don't appear to be any macOS artifacts @ com.formdev:flatlaf:dylib:macos-arm64:PR-988-SNAPSHOT |
|
Otherwise I can confirm success on arm64 macos (using artifacts rather than snapshots) |
|
I implemented the system file chooser 5 different times, once as a open dialog and 4 times as an save as dialog. One save dialog launched in a minimised state, which needs a trick to maximise. I've only seen this in Preview.app and I don't understand how it's triggered, I didn't do anything special. |
|
Reflecting on the minimised dialog and Preview.app I think I had used this option in my app to save as PDF Could that be the trigger? Edit: It only happens on first launch, I'm thinking it's just a quirk |
Not sure what you mean by "minimized state" 😕
what trick? |
|
Also wondering what it would take to centre dialog on app window, I only adapted my App quickly and may have missed something. |
|
I have confirmed working in Windows 11. I may be nitpicking but dialogs are wider than my app window and have to be resized. |
|
I've tested in Xfce4 now, all working. I'm also able to do a side by side comparison with JFileChooser and in my opinion the platform needs to incorporate this code, JFileChooser is years old and not fit for purpose. How hard would it be to upstream this PR, I mean it looks really bureaucratic to me but I'm not a JDK dev? |
|
One thing that is missing is passing a |
|
Not sure if a cross-platform solution for FileSystemView would be possible |
@Scoty @KlemenDEV this is not possible because native file dialogs do not support this. They show always the file system. |
|
This is amazing, can't wait to see this in a release! :D |
|
Just realized that there are some unanswered questions...
@ctipper unfortunately there is no way to control this behavior.
@ctipper There is no way to control size or location of native file dialogs. The operating systems decide where to show it and its size.
@ctipper There is no Windows API to control file dialog size. |
|
Thanks for testing and the feedback 👍 😃 |
@DevCharly This presented no difficulty as state is preserved, it just appears initially so only mild confusion. Weirdly it seemed to know that it was set for PDF so many users will not discover this
@DevCharly Let's hope it maintains state, I am not sitting at my test machine This is all good work, though the Windows feature is the main motivation for me. JFileChooser is not a very useful dialog on Windows. Looking forward to the release. |
|
Once again, thanks for this feature. One step forward to being JavaFX free in our software :D I have tried to implement the solution for our project (MCreator/MCreator@master...KlemenDEV:MCreator:system_file_chooser) and have noticed one problem. With e.g. JavaFX that also uses native dailogs, one can defina a file filter such as "_file_suffix.png", so it only shows files that end with suffix + extension, but your file filter prevents dots in extensions and auto-applies dots, preventing this use case. Since JavaFX can do it, I think this should not be limitation of system chooser options. Would it be possible to implement something like this for this library too? Other than that, seems to work very well, nicely done! :) |

Class
SystemFileChooser(in packagecom.formdev.flatlaf.util) allows using operating system file dialogs in Java Swing applications.Details: https://www.formdev.com/flatlaf/system-file-chooser/
Windows
macOS
Linux
Light or Dark ?
On Windows and Linux, the system file dialogs are shown in system appearance. If application uses FlatLaf Dark, but system uses Light appearance, then file dialogs are also shown in Light appearance. Have not found a way to control light/dark appearance on those platforms.
On macOS, system file dialogs are shown in same appearance as FlatLaf. If application uses FlatLaf Dark, but system uses Light appearance, then file dialogs are shown in Dark appearance.
Background story
Before starting this task, the basic idea was to implement some (small) native
code for Windows and use AWT
FileDialogon macOS and Linux. Thought that couldbe done in 2 or 3 days. I was so wrong...
Turns out that AWT
FileDialogdoes not provide necessary features (e.g."Select Folder"), window modality does not work, macOS file dialog does not
offer a "file filter" combobox, etc.
So implemented (larger) native code for Windows, macOS and Linux. This was
difficult because I never used GTK before and my macOS Cocoa skills were also limited.
In the end it took about 4 weeks to implement, test and document this feature.
If I had known that, I probably wouldn't have started it...
So if you use FlatLaf in a commercial application, please consider sponsoring
FlatLaf development: https://www.formdev.com/flatlaf/sponsor/
Thank you.