@Override public void start(Stage primaryStage) { primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() { @Override public void handle(WindowEvent e) { Platform.exit(); System.exit(0); } }); }
/** * Adds an OnCloseRequest handle to the window which will store the position, * size and maximized status of the window. * * @param stage the stage to read settings from * @param name the name under which we store the settings */ public static void applySaveOnCloseMethod(Stage stage, String name){ stage.setOnCloseRequest( ev -> { try { Preferences stagePreferences = PREFERENCES.node(name); if( stage.isMaximized() ){ stagePreferences.putBoolean(WINDOW_MAXIMIZED, true); } else { stagePreferences.putBoolean(WINDOW_MAXIMIZED, false); stagePreferences.putDouble(WINDOW_X_POS, stage.getX()); stagePreferences.putDouble(WINDOW_Y_POS, stage.getY()); stagePreferences.putDouble(WINDOW_WIDTH, stage.getWidth()); stagePreferences.putDouble(WINDOW_HEIGHT, stage.getHeight()); } stagePreferences.flush(); } catch (final BackingStoreException ex) { LOGGER.error(ex, "Could not flush preferences for window " + name); } }); }
public void showExportXPathToRuleWizard() { ExportXPathWizardController wizard = new ExportXPathWizardController(xpathExpressionProperty()); FXMLLoader loader = new FXMLLoader(getClass().getResource("fxml/xpath-export-wizard.fxml")); loader.setController(wizard); final Stage dialog = new Stage(); dialog.initOwner(designerRoot.getMainStage()); dialog.setOnCloseRequest(e -> wizard.shutdown()); dialog.initModality(Modality.WINDOW_MODAL); Parent root; try { root = loader.load(); } catch (IOException e) { throw new RuntimeException(e); } Scene scene = new Scene(root); //stage.setTitle("PMD Rule Designer (v " + PMD.VERSION + ')'); dialog.setScene(scene); dialog.show(); }
stage.setOnCloseRequest(e -> mainController.shutdown());
@Override public void start(Stage mainStage) throws Exception { Scene scene = new Scene(new Region()); mainStage.setWidth(640); mainStage.setHeight(480); mainStage.setScene(scene); //this makes all stages close and the app exit when the main stage is closed mainStage.setOnCloseRequest(e -> Platform.exit()); //add real stuff to the scene... //open secondary stages... etc... }
@Override public void start(Stage stage) { stage.setOnCloseRequest( event -> System.out.println("Close Requested") );
@Override public void start(Stage primaryStage) { primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() { @Override public void handle(WindowEvent event) { ThreadPool.shutdown(); } }); initGui(primaryStage); initData(); }
public void start(Stage primaryStage) { // do all the regular stuff. primaryStage.setOnCloseRequest(E -> { // perform actions before closing }); }
public class MYUI extends Application implements EventHandler<WindowEvent> { @Override public void start(Stage s) throws Exception { s.setOnCloseRequest(this); } @Override public void stop() throws Exception { } @Override public void handle(WindowEvent event) { [...] your code } }
@Override public void start(Stage primaryStage) { this.primaryStage = primaryStage; injector = initInjector(); Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionLogger()); initSejda(); cleanIfRequired(); primaryStage.setScene(initScene()); primaryStage.getIcons().addAll(injector.instancesOfType(Image.class)); primaryStage.setTitle(injector.instance(Pdfsam.class).name()); primaryStage.setOnCloseRequest(e -> Platform.exit()); requestPremiumModulesDescriptionIfRequired(); initWindowsStatusController(primaryStage); initDialogsOwner(primaryStage); initActiveModule(); loadWorkspaceIfRequired(); initOpenButtons(); primaryStage.show(); requestCheckForUpdateIfRequired(); requestLatestNewsIfRequired(); eventStudio().addAnnotatedListeners(this); closeSplash(); STOPWATCH.stop(); LOG.info(DefaultI18nContext.getInstance().i18n("Started in {0}", DurationFormatUtils.formatDurationWords(STOPWATCH.getTime(), true, true))); new InputPdfArgumentsController().accept(rawParameters); }
@Override public void start(Stage stage) { Scene scene = new Scene(new Region()); stage.setScene(scene); /* ... OTHER STUFF ... */ stage.setOnCloseRequest(e -> { Platform.exit(); System.exit(0); }); }
import javafx.application.Application; import javafx.event.EventHandler; import javafx.stage.Stage; import javafx.stage.WindowEvent; public class Test extends Application { @Override public void start(final Stage stage) throws Exception { stage.setOnCloseRequest(new EventHandler<WindowEvent>() { public void handle(final WindowEvent windowEvent) { windowEvent.consume(); } }); stage.show(); } public static void main(String[] args) { Application.launch(args); } }
import javafx.application.Application; import javafx.event.EventHandler; import javafx.stage.Stage; import javafx.stage.WindowEvent; public class Boom extends Application { @Override public void start(final Stage primary) { System.out.println(com.sun.javafx.runtime.VersionInfo.getRuntimeVersion()); primary.setOnCloseRequest(new EventHandler<WindowEvent>() { @Override public void handle(WindowEvent e) { e.consume(); } }); primary.show(); } public static void main(String[] args) { launch(args); } }
Stage stage = new Stage(); stage.initStyle(StageStyle.UNDECORATED); ctl.Glisse(home_page_p, stage, home_page_s); stage.setScene(home_page_s); // Adding a event handler to be fired on the event of stage being closed stage.setOnCloseRequest((WindowEvent event) -> { // Perform some action when the stage is closed ancr.setEffect(null); // ancr is a reference to the anchorpane }
@Override public void start(Stage primaryStage) { Scene scene = new Scene(new Group(), 100, 100); primaryStage.setOnCloseRequest(evt -> { Alert alert = new Alert(Alert.AlertType.CONFIRMATION, "Do you really want to close this applicetion?", ButtonType.YES, ButtonType.NO); ButtonType result = alert.showAndWait().orElse(ButtonType.NO); if (ButtonType.NO.equals(result)) { // no choice or no clicked -> don't close evt.consume(); } }); primaryStage.setScene(scene); primaryStage.show(); }
/** * Makes sure that this media player is stopped and disposed when the user closes the stage for this screen. * * @param embeddingStage The stage for which to listen to close requests */ @Override public void setStage(final Stage embeddingStage) { embeddingStage.setOnCloseRequest(e -> { final MediaPlayer mediaPlayer = mediaView.getMediaPlayer(); if (mediaPlayer != null) { mediaPlayer.stop(); mediaPlayer.dispose(); } }); } }
Stage newStage;//declare a new stage out of the action event @FXML private void andNewBtnAction(ActionEvent event) throws IOException { newStage = new Stage(); newStage.setTitle("Add New"); //container of your parent FXML (you can set blur effect to your parent once your new window open ) stackPane.setEffect(new GaussianBlur(10)); newStage.setScene(new Scene(FXMLLoader. load(URL_TO_YOUR_FXML)); newStage.setResizable(false); newStage.initModality(Modality.WINDOW_MODAL); newStage.initOwner(YOUR_PRIMARY_STAGE); newStage.show(); newStage.setOnCloseRequest((WindowEvent t) -> { stackPane.setEffect(null);//remove the effect after you close the new window newStage = null; }); }
@Override @FXML public void initialize() { // NOPMD super.initialize(); // CREATION OF STAGE SCENE AND PANE this.stage = new Stage(); this.scene = new Scene(this.recorderPane); this.stage.setScene(this.scene); // SETTING EXIT ACTIONS this.stage.setOnCloseRequest(e -> { this.stopSensor(); Platform.exit(); System.exit(0); }); // CHARGE THE CSS this.chargeSceneSheets(FXMLScreens.HOME); this.stage.show(); }
@Override public void start(Stage primaryStage) throws Exception { FXMLLoader loader = new FXMLLoader(); loader.setLocation(getClass().getResource(getClass().getSimpleName() + ".fxml")); loader.setController(this); loader.load(); controller.setMainWindow(primaryStage); controller.enableNetworkProcessorClientProperty().set(true); controller.setLidarScanMessageConsumer(lidarScanLogViewer::renderLidarScanMessage); lidarScanLogViewer.start(); lidarScanLogWriterControlPaneController.initialize(controller, lidarScanLogViewer); lidarScanLogReaderControlPaneController.initialize(controller); View3DFactory view3dFactory = View3DFactory.createSubscene(); view3dFactory.addCameraController(); view3dFactory.addWorldCoordinateSystem(0.3); view3dFactory.attachSubSceneTo(centerPane); view3dFactory.addNodeToView(lidarScanLogViewer.getRoot()); primaryStage.setTitle(getClass().getSimpleName()); primaryStage.setScene(new Scene(mainPane, 600, 400)); primaryStage.show(); primaryStage.setOnCloseRequest(event -> stop()); }
@Override public void start(Stage primaryStage) { primaryStage.setTitle("Setup Credentials File"); // primaryStage.initModality(Modality.APPLICATION_MODAL); GridPane grid = createGrid(); int row = 0; row = addInputFields(grid, row); setDefaultValues(); row = addButtons(grid, row); row = addMessageText(grid, row); Scene scene = new Scene(grid, 700, 275); // Scene scene = new Scene(grid); primaryStage.setScene(scene); primaryStage.setOnCloseRequest(closeEventHandler()); primaryStage.show(); }