Window window = newVal.windowProperty().get(); if( window != null ){ window.setOnCloseRequest( (ev) -> closeWindow() ); } else { newVal.windowProperty().addListener( (ob, oldW, newW) -> { newW.setOnCloseRequest( (ev) -> closeWindow() ); });
@Override public void postInit(Scene scene) { ... scene.windowProperty().addListener(new InvalidationListener() { @Override public void invalidated(Observable observable) { scene.getWindow().setOnCloseRequest(e -> { e.consume(); action("exit").handle(new ActionEvent()); }); scene.windowProperty().removeListener(this); } }); }
/** * Get the window property of a node * * @param n * the node the window property to observe * @return the property */ public static ObservableValue<Window> windowProperty(Node n) { ObjectProperty<Window> w = new SimpleObjectProperty<Window>(); ChangeListener<Window> l = (o, oldV, newV) -> w.set(newV); n.sceneProperty().addListener((o, oldV, newV) -> { if (oldV != null) { oldV.windowProperty().removeListener(l); } if (newV != null) { newV.windowProperty().addListener(l); } }); return w; }
/** * Get the window property of a node * * @param n * the node the window property to observe * @return the property */ public static ObservableValue<Window> windowProperty(Node n) { ObjectProperty<Window> w = new SimpleObjectProperty<Window>(); ChangeListener<Window> l = (o, oldV, newV) -> w.set(newV); n.sceneProperty().addListener((o, oldV, newV) -> { if (oldV != null) { oldV.windowProperty().removeListener(l); } if (newV != null) { newV.windowProperty().addListener(l); } }); return w; }
public static void bindToStageTitle(Node n, StringProperty property) { ChangeListener<Window> windowListener = (observable, oldValue, newValue) -> { if (oldValue != null && oldValue instanceof Stage) { ((Stage) oldValue).titleProperty().unbindBidirectional(property); } if (newValue != null && newValue instanceof Stage) { ((Stage) newValue).titleProperty().bindBidirectional(property); } }; n.sceneProperty().addListener((observable, oldValue, newValue) -> { if (oldValue != null) { oldValue.windowProperty().removeListener(windowListener); } if (newValue != null) { newValue.windowProperty().addListener(windowListener); if (newValue.getWindow() != null && newValue.getWindow() instanceof Stage) { ((Stage) newValue.getWindow()).titleProperty().bindBidirectional(property); } } }); if (n.getScene() != null) { n.getScene().windowProperty().addListener(windowListener); } }
public static void registerListenerForWindowFocus(Node n, InvalidationListener l) { ChangeListener<Window> windowListener = (observable, oldValue, newValue) -> { if (oldValue != null) { oldValue.focusedProperty().removeListener(l); } if (newValue != null) { newValue.focusedProperty().addListener(l); } }; n.sceneProperty().addListener((observable, oldValue, newValue) -> { if (oldValue != null) { oldValue.windowProperty().removeListener(windowListener); } if (newValue != null) { newValue.windowProperty().addListener(windowListener); if (newValue.getWindow() != null) { newValue.getWindow().focusedProperty().addListener(l); l.invalidated(newValue.getWindow().focusedProperty()); } } }); if (n.getScene() != null) { n.getScene().windowProperty().addListener(windowListener); } }
public static void registerListenerForStageFullscreen(Node n, InvalidationListener l) { ChangeListener<Window> windowListener = (observable, oldValue, newValue) -> { if (oldValue != null && oldValue instanceof Stage) { ((Stage) oldValue).fullScreenProperty().removeListener(l); } if (newValue != null && newValue instanceof Stage) { ((Stage) newValue).fullScreenProperty().addListener(l); } }; n.sceneProperty().addListener((observable, oldValue, newValue) -> { if (oldValue != null) { oldValue.windowProperty().removeListener(windowListener); } if (newValue != null) { newValue.windowProperty().addListener(windowListener); if (newValue.getWindow() != null && newValue.getWindow() instanceof Stage) { ((Stage) newValue.getWindow()).fullScreenProperty().addListener(l); l.invalidated(((Stage) newValue.getWindow()).fullScreenProperty()); } } }); if (n.getScene() != null) { n.getScene().windowProperty().addListener(windowListener); } }
@SuppressWarnings("null") @Override protected Node createWindowArea() { BorderPane root = new BorderPane(); getStyleClass().addAll("default-window", "decorated-root"); //$NON-NLS-1$ //$NON-NLS-2$ Node dialogTitleBar = createTitleBar(); this.dialogAreaNode = (TitleAreaNode) dialogTitleBar; registerTitleBar(dialogTitleBar); this.titleProperty = ((TitleAreaNode) dialogTitleBar).titleProperty(); root.setTop(dialogTitleBar); dialogTitleBar.applyCss(); sceneProperty().addListener((o) -> { Scene s = getScene(); if (s != null) { if (s.getWindow() != null) { handleStageAttached(); } else { s.windowProperty().addListener((o2) -> { if (s.getWindow() != null) { handleStageAttached(); } }); } } }); this.trimPane = new BorderPane(); root.setCenter(this.trimPane); this.contentProperty = this.trimPane.centerProperty(); return root; }
@SuppressWarnings("null") @Override protected Node createWindowArea() { BorderPane root = new BorderPane(); getStyleClass().addAll("default-window", "decorated-root"); //$NON-NLS-1$ //$NON-NLS-2$ Node dialogTitleBar = createTitleBar(); this.dialogAreaNode = (TitleAreaNode) dialogTitleBar; registerTitleBar(dialogTitleBar); this.titleProperty = ((TitleAreaNode) dialogTitleBar).titleProperty(); root.setTop(dialogTitleBar); dialogTitleBar.applyCss(); sceneProperty().addListener((o) -> { Scene s = getScene(); if (s != null) { if (s.getWindow() != null) { handleStageAttached(); } else { s.windowProperty().addListener((o2) -> { if (s.getWindow() != null) { handleStageAttached(); } }); } } }); this.trimPane = new BorderPane(); root.setCenter(this.trimPane); this.contentProperty = this.trimPane.centerProperty(); return root; }
@SuppressWarnings("null") @Override protected Node createWindowArea() { BorderPane root = new BorderPane(); getStyleClass().addAll("default-window", "decorated-root"); //$NON-NLS-1$ //$NON-NLS-2$ Node dialogTitleBar = createTitleBar(); this.dialogAreaNode = (TitleAreaNode) dialogTitleBar; registerTitleBar(dialogTitleBar); this.titleProperty = ((TitleAreaNode) dialogTitleBar).titleProperty(); root.setTop(dialogTitleBar); dialogTitleBar.applyCss(); sceneProperty().addListener((o) -> { Scene s = getScene(); if (s != null) { if (s.getWindow() != null) { handleStageAttached(); } else { s.windowProperty().addListener((o2) -> { if (s.getWindow() != null) { handleStageAttached(); } }); } } }); this.trimPane = new BorderPane(); root.setCenter(this.trimPane); this.contentProperty = this.trimPane.centerProperty(); return root; }
@SuppressWarnings("null") @Override protected Node createWindowArea() { BorderPane root = new BorderPane(); getStyleClass().addAll("default-window", "decorated-root"); //$NON-NLS-1$ //$NON-NLS-2$ Node dialogTitleBar = createTitleBar(); this.dialogAreaNode = (TitleAreaNode) dialogTitleBar; registerTitleBar(dialogTitleBar); this.titleProperty = ((TitleAreaNode) dialogTitleBar).titleProperty(); root.setTop(dialogTitleBar); dialogTitleBar.applyCss(); sceneProperty().addListener((o) -> { Scene s = getScene(); if (s != null) { if (s.getWindow() != null) { handleStageAttached(); } else { s.windowProperty().addListener((o2) -> { if (s.getWindow() != null) { handleStageAttached(); } }); } } }); this.trimPane = new BorderPane(); root.setCenter(this.trimPane); this.contentProperty = this.trimPane.centerProperty(); return root; }