From 983b341f33f4c6b81941eb3a2e9971343da8e228 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Thu, 1 Apr 2021 01:07:35 +0200 Subject: [PATCH] Native window decorations: fixed loading of native library when using JPMS for application (issue #289) --- CHANGELOG.md | 4 +++- .../flatlaf/ui/FlatWindowsNativeWindowBorder.java | 3 +-- .../java/com/formdev/flatlaf/util/NativeLibrary.java | 12 ++++++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6779f5b3..625ef98d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,11 +5,13 @@ FlatLaf Change Log #### Fixed bugs -- Fixed crash when running in Webswing. (issue #290) +- Native window decorations: Fixed loading of native library when using Java + Platform Module System (JPMS) for application. (issue #289) - Native window decorations: Removed superfluous pixel-line at top of screen when window is maximized. (issue #296) - Button and ToggleButton: Do not paint background of disabled (and unselected) toolBar buttons. (issue #292; regression since fixing #112) +- Fixed crash when running in Webswing. (issue #290) ## 1.1.1 diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatWindowsNativeWindowBorder.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatWindowsNativeWindowBorder.java index 0ae91536..4b909a05 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatWindowsNativeWindowBorder.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatWindowsNativeWindowBorder.java @@ -103,8 +103,7 @@ class FlatWindowsNativeWindowBorder if( SystemInfo.isX86_64 ) libraryName += "_64"; - nativeLibrary = new NativeLibrary( libraryName, - FlatWindowsNativeWindowBorder.class.getClassLoader(), true ); + nativeLibrary = new NativeLibrary( libraryName, null, true ); } // check whether native library was successfully loaded diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/NativeLibrary.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/NativeLibrary.java index 06cfc36c..b333ef1f 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/NativeLibrary.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/NativeLibrary.java @@ -42,9 +42,15 @@ public class NativeLibrary /** * Load native library from given classloader. + *

+ * Note regarding Java Platform Module System (JPMS): + * If classloader is {@code null}, the library can be only loaded from the module + * that contains this class. + * If classloader is not {@code null}, then the package that contains the library + * must be specified as "open" in module-info.java of the module that contains the library. * * @param libraryName resource name of the native library (without "lib" prefix and without extension) - * @param classLoader the classloader used to locate the library + * @param classLoader the classloader used to locate the library, or {@code null} * @param supported whether the native library is supported on the current platform */ public NativeLibrary( String libraryName, ClassLoader classLoader, boolean supported ) { @@ -68,7 +74,9 @@ public class NativeLibrary libraryName = decorateLibraryName( libraryName ); // find library - URL libraryUrl = classLoader.getResource( libraryName ); + URL libraryUrl = (classLoader != null) + ? classLoader.getResource( libraryName ) + : NativeLibrary.class.getResource( "/" + libraryName ); if( libraryUrl == null ) { log( "Library '" + libraryName + "' not found", null ); return false;