更新时间:2023-12-05 22:10:34
我编写了这个控制器来跟踪不同的场景图。
I wrote this controller to keep track of the different scenegraphes.
public class ScreenController {
private HashMap<String, Pane> screenMap = new HashMap<>();
private Scene main;
public ScreenController(Scene main) {
this.main = main;
}
protected void addScreen(String name, Pane pane){
screenMap.put(name, pane);
}
protected void removeScreen(String name){
screenMap.remove(name);
}
protected void activate(String name){
main.setRoot( screenMap.get(name) );
}
}
所以我可以写:
ScreenController screenController = new ScreenController(scene);
screenController.add("calculator", FXMLLoader.load(getClass().getResource( "calculator.fxml" )));
screenController.add("testSwitch", FXMLLoader.load(getClass().getResource( "TestSwitch.fxml" )));
screenController.activate("calculator");
这是全屏应用程序的解决方法,每次舞台切换时都会显示MacOS全屏转换它的场景。
This was a workaround for a fullscreen application, where the MacOS fullscreen transition was shown every time a stage switches its scene.