Skip to content

Instantly share code, notes, and snippets.

@FibreFoX
Created January 8, 2015 20:09
Show Gist options
  • Save FibreFoX/294012b16fa10519674b to your computer and use it in GitHub Desktop.
Save FibreFoX/294012b16fa10519674b to your computer and use it in GitHub Desktop.
After some research if found a way to have a "slashscreen" within javafx 8 using native-bundle (and having CDI via OWB and Deltaspike)
import java.util.logging.Logger;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.event.ActionEvent;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javax.inject.Inject;
public class SomeJavaFXClassWithCDI extends javafx.application.Application {
@Inject
private Logger logger;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
// due to the nature of preloader being ignored within native-package, show it here
SplashScreen splashScreen = new SplashScreen();
splashScreen.show(new Stage(StageStyle.TRANSPARENT));
// needed for callback
final SomeJavaFXClassWithCDI launcherThread = this;
// for splashscreen to be shown, its needed to delay everything else as parallel task/thread (it would block otherwise)
Task cdiTask = new Task<Void>() {
@Override
protected Void call() throws Exception {
// boot CDI after javaFX-splash (this will "halt" the application due to the work done by CDI-provider
bootCDI(launcherThread);
// push javaFX-work to javaFX-thread
Platform.runLater(() -> {
primaryStage.setTitle("Some Title");
// TODO prepare your stage here !
// smooth fade-out of slashscreen
splashScreen.fadeOut((ActionEvent event) -> {
primaryStage.show();
splashScreen.hide();
});
});
return null;
}
};
// run task
new Thread(cdiTask).start();
}
private void bootCDI(SomeJavaFXClassWithCDI launcherThread) {
// boot up CDI (simple class wrapping all CDI-relevant things)
CDIHelper.bootCDI();
CDIHelper.injectIntoTarget(launcherThread);
}
@Override
public void stop() throws Exception {
super.stop();
CDIHelper.shutdownCDI();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment