기본 응용 프로그램 창 앞에 모달 창을 시작해야하는 간단한 JavaFX 응용 프로그램을 빌드하고 있습니다. 아래 코드를 사용하여 모달 창을 한 번 실행하고 닫을 수 있습니다. 나는 다시 시작하려고하면, 내가받을 : 나는 봄 컨트롤러/FXML보기 의존성 주입 방법은 여기에 설명 된 사용하고두 번째로 모달 대화 상자를 시작할 때 JavaFX가 "다른 씬의 루트로 이미 설정되었습니다"예외가 발생했습니다.
java.lang.IllegalArgumentException: BorderPane[id=root, styleClass=root]is already set as root of another scene
: http://www.zenjava.com/2012/02/20/porting-first-contact-to-spring/
내가 프로그래밍 방식으로 장면을 생성하고 숨길 수 있어요/FXML/Spring Controller 주입을 사용하지 않고 간단한 대화 상자를 표시하십시오. 이것은 잘 작동합니다.
startButton을 클릭 할 때마다 새 Scene()을 만들고 있기 때문에 'root로 설정'예외에 대해 설명 할 수 없습니다. 첫 번째 장면은 첫 번째 장면이 닫힐 때마다 사라져야합니다.
관련 파일은 아래에 있습니다.
MainTabPanel.java - 내 응용 프로그램의 기본보기. 여기에는 모달 창을 시작하기 위해 클릭 한 'startButton'이 포함됩니다. 다음 @Inject private ActivePresentation activePresentation;
이 startButton을 클릭하면 모달을 시작하려고 시도 초기화() 방법 :로
ActivePresentation 컨트롤러 /보기가 주입된다.
@FXML
public void initialize()
{
availableReceiversIdColumn.setCellValueFactory(new PropertyValueFactory("id"));
availableReceiversFirmwareVersionColumn.setCellValueFactory(new PropertyValueFactory("firmwareVersion"));
availableReceiversModelColumn.setCellValueFactory(new PropertyValueFactory("model"));
availableReceiversChannelColumn.setCellValueFactory(new PropertyValueFactory("channel"));
ObservableList<String> responseTypes = FXCollections.observableArrayList();
responseTypes.add("Single Response Alpha");
responseTypes.add("Single Response Numeric");
responseTypeChoiceBox.setItems(responseTypes);
startButton.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent e)
{
Stage stage = new Stage();
stage.initModality(Modality.APPLICATION_MODAL);
presentationResponseService.startPresentation();
activePresentation.populateResponses(null);
activePresentation.populateResults(null);
Scene activePresentationScene = new Scene(activePresentation.getView());
activePresentationScene.getStylesheets().add("styles.css");
stage.setScene(activePresentationScene);
stage.setTitle("Active Presentation");
stage.showAndWait();
}
});
}
closeButton은 다음과 같이 모달 대화 상자에 정의되어 있습니다.
closeButton.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent e)
{
presentationResponseService.closePresentation();
Stage stage = (Stage) root.getScene().getWindow();
stage.close();
}
});
ActivePresentation Bean 및 FXML 로더에 대한 Java 기반 Spring 구성은 다음과 같습니다. (: 당신은 요 다시 열 시도 할 수 있습니다 로직)
@Bean
public ActivePresentation activePresentation()
{
return loadPresenter("/fxml/ActivePresentation.fxml");
}
FXML 로더
private <T> T loadPresenter(String fxmlFile)
{
try
{
FXMLLoader loader = new FXMLLoader();
loader.load(getClass().getResourceAsStream(fxmlFile));
return (T) loader.getController();
} catch (IOException e)
{
throw new RuntimeException(String.format("Unable to load FXML file '%s'", fxmlFile), e);
}
}
보인다 무대가 (당신이 요 다시 열 시도 할 수 있습니다 로직) JFX의 제어하에 여전히 :
나는 아래의 코드를 참조 팝업 창은 이미 장면이 있다면 확인하여 관리 하지만 이전에 아직 살아있는 동안 매번 무대를 만들면 stage.close() 근처에 stage.setScene (null)을 추가 할 수 있습니까?또는 매번 같은 장면이나 같은 무대를 사용합니까? –