steffen678 / nativejfilechooser Goto Github PK
View Code? Open in Web Editor NEWNative file chooser for Swing using JavaFX if available
License: BSD 2-Clause "Simplified" License
Native file chooser for Swing using JavaFX if available
License: BSD 2-Clause "Simplified" License
Hi,
I know the JavaFx FileChooser doesn't support multiple folder selection, but do you have any idea on how to get around that issue? I dont really want to miss the native filechooser, but selecting multiple folders is somewhat important for my application.
Hi, I've been trying to use this as part of a Java Swing app my class uses. It seems to work fine most of the time, but on macOS, it occasionally hangs when it tries to show the dialog, and I can't figure out why. I did not write the app, so I can't really re-architect it, and maybe this issue is just because of how the code is written...
In an event handler, the app calls showOpenDialog
. The Runnable
does run, but on the fileChooser.showOpenDialog(null);
line, the program hangs, eats a bunch of CPU, and never shows the dialog.
I've tried using jdb to debug, and found that that method is getting hung up in a call to getFocusOwner
within the macOS support. It starts some kind of native AWT loop and never stops.
It seems to be a deadlock - if I interrupt the AWT Event Queue thread (the one waiting on the CountdownLatch
), everything reappears, though it causes an InterruptedException
so the dialog doesn't actually work. It's like the Event Queue thread is waiting on the JFX App thread, which is waiting on the Event Queue thread...
It feels like I shouldn't be calling showOpenDialog
from the AWT Event Queue thread, but don't most applications do so? I mean, you handle a menu event or button by opening the dialog.
Is this an architectural issue? Or is something else going wrong?
Edit: Creating a dummy thread to call showOpenDialog
does seem to work. I think this is architectural.
It looks like NativeJFileChooser blocks and the current thread until the file dialog is closed (due to the latch in showOpenDialog()
), but if this method is invoked from the EDT it blocks the whole application.
Check of presence of JavaFX is useless because you directly depend on the JavaFX classes. NativeJFileChooser won't be loaded at runtime. Fox example, in Java 14 environment:
--- exec-maven-plugin:3.0.0:exec (default-cli) @ Test ---
Exception in thread "main" java.lang.NoClassDefFoundError: javafx/stage/DirectoryChooser
at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3244)
at java.base/java.lang.Class.getDeclaredMethod(Class.java:2551)
at java.desktop/java.awt.Component.isCoalesceEventsOverriden(Component.java:6321)
at java.desktop/java.awt.Component$3.run(Component.java:6275)
at java.desktop/java.awt.Component$3.run(Component.java:6273)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:312)
at java.desktop/java.awt.Component.checkCoalescing(Component.java:6272)
at java.desktop/java.awt.Component.<init>(Component.java:6241)
at java.desktop/java.awt.Container.<init>(Container.java:296)
at java.desktop/javax.swing.JComponent.<init>(JComponent.java:598)
at java.desktop/javax.swing.JFileChooser.<init>(JFileChooser.java:347)
at java.desktop/javax.swing.JFileChooser.<init>(JFileChooser.java:295)
at li.flor.nativejfilechooser.NativeJFileChooser.<init>(NativeJFileChooser.java:86)
at test.JFileChooserWithProps.main(JFileChooserWithProps.java:89)
Caused by: java.lang.ClassNotFoundException: javafx.stage.DirectoryChooser
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 15 more
Here is the log, im on a macOS 11.6.4:
at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3166)
at java.base/java.lang.Class.getDeclaredMethod(Class.java:2473)
at java.desktop/java.awt.Component.isCoalesceEventsOverriden(Component.java:6339)
at java.desktop/java.awt.Component$3.run(Component.java:6293)
at java.desktop/java.awt.Component$3.run(Component.java:6291)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.desktop/java.awt.Component.checkCoalescing(Component.java:6290)
at java.desktop/java.awt.Component.<init>(Component.java:6259)
at java.desktop/java.awt.Container.<init>(Container.java:296)
at java.desktop/javax.swing.JComponent.<init>(JComponent.java:599)
at java.desktop/javax.swing.JFileChooser.<init>(JFileChooser.java:360)
at java.desktop/javax.swing.JFileChooser.<init>(JFileChooser.java:338)
at li.flor.nativejfilechooser.NativeJFileChooser.<init>(NativeJFileChooser.java:96)
at MainClass.main(LambdaExpressions.java:23)
Caused by: java.lang.ClassNotFoundException: javafx.stage.DirectoryChooser
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 15 more```
Hi there, I tried somethings similar in the past but I was missing modality support. Any ideas on how to achieve this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.