Javafx открывает еще один fxml в другом окне с кнопкой
Возможно ли в javafx открывать новые ступени (окна) из другого fxml с помощью кнопки?
Спасибо за ответы.
Ответы
Ответ 1
Используйте код ниже при нажатии кнопки:
try {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("Demo.fxml"));
Parent root1 = (Parent) fxmlLoader.load();
Stage stage = new Stage();
stage.initModality(Modality.APPLICATION_MODAL);
stage.initStyle(StageStyle.UNDECORATED);
stage.setTitle("ABC");
stage.setScene(new Scene(root1));
stage.show();
}
Ответ 2
Мне пришлось немного изменить код, и он отлично работает. Еще раз спасибо за код!
public void pressButton(ActionEvent event) throws Exception {
try {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/A.fxml"));
Parent root1 = (Parent) fxmlLoader.load();
Stage stage = new Stage();
stage.setScene(new Scene(root1));
stage.show();
} catch(Exception e) {
e.printStackTrace();
}
}