Java examples for JavaFX:Stage
register Listener For JavaFX Stage Fullscreen
//package com.java2s; import javafx.beans.InvalidationListener; import javafx.beans.value.ChangeListener; import javafx.scene.Node; import javafx.stage.Stage; import javafx.stage.Window; public class Main { 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); }/*from w ww . j av a 2s . c om*/ 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); } } }