SwiftUI 2: the way to open view in new window

Update: Xcode 14 / macOS 13 Now we can explicitly open needed window giving it identifier and use it in openWindow environment action. class BookViewModel: ObservableObject {} class AppState: ObservableObject { @Published var selectedBook: BookViewModel? } @main struct SwiftUI2_MacApp: App { @StateObject var appState = AppState() @SceneBuilder var body: some Scene { WindowGroup { // … Read more

How to switch scenes in JavaFX

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) ); … Read more

Loading new fxml in the same scene

Why your code does not work The loader creates a new AnchorPane, but you never add the new pane to a parent in the scene graph. Quick Fix Instead of: content = (AnchorPane) FXMLLoader.load(“vista2.fxml”); Write: content.getChildren().setAll(FXMLLoader.load(“vista2.fxml”)); Replacing the content children with your new vista. The content itself remains in the scene graph, so when you … Read more