Files
WebClient/src/main/java/org/openautonomousconnection/webclient/FxBootstrap.java

34 lines
891 B
Java
Raw Normal View History

2026-02-14 22:16:15 +01:00
package org.openautonomousconnection.webclient;
2026-02-08 22:36:42 +01:00
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* Initializes the JavaFX Toolkit exactly once for Swing embedding.
*/
public final class FxBootstrap {
private static final AtomicBoolean INITIALIZED = new AtomicBoolean(false);
private FxBootstrap() {
// Utility class
}
/**
* Ensures JavaFX Toolkit is initialized.
* Must be called before any Platform.runLater() usage.
*/
public static void ensureInitialized() {
if (!INITIALIZED.compareAndSet(false, true)) {
return;
}
// Creating a JFXPanel initializes the JavaFX toolkit in Swing apps.
new JFXPanel();
2026-02-14 22:16:15 +01:00
// Keep JavaFX runtime alive even if last window closes.
2026-02-08 22:36:42 +01:00
Platform.setImplicitExit(false);
}
}