34 lines
908 B
Java
34 lines
908 B
Java
|
|
package org.openautonomousconnection.webclient.recode;
|
||
|
|
|
||
|
|
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();
|
||
|
|
|
||
|
|
// Optional: keep JavaFX runtime alive even if last window closes.
|
||
|
|
Platform.setImplicitExit(false);
|
||
|
|
}
|
||
|
|
}
|