![](/img/trans.png)
[英]Scene Builder 8.0 & Intelli. From one scene to another scene
[英]Can I set the value of a TextField in one scene from another scene, while both scenes are showing?
我正在嘗試從另一個場景中選擇的值的場景填充TextField。
所以有一個場景(我稱之為父場景)有一個TextField和一個打開另一個場景的按鈕(我稱之為子場景)。 子場景有一個TableView,它選擇了我想要設置為父場景的TextField的值。 我知道只有在沒有打開TextField的場景時才會這樣做,在我的例子中,子場景的舞台被設置為showAndWait。 所以我認為我需要獲取父場景的舞台並將其設置為子控制器下面的select()方法中的舞台字段。
//來自子控制器的方法,從tableview中選擇一行時調用
public void select() throws IOException
{
Class class = (Class)table.getSelectionModel().getSelectedItem();
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getClassLoader().getResource("parentStage.fxml"));
Parent parent = loader.load();
Stage stage = // here i need to pass the parent stage I think;
stage.initModality(Modality.APPLICATION_MODAL);
ParentController parentController = loader.getController();
table.setOnMouseClicked(event -> {
if(event.getClickCount()==2){
parentController.setTextField(new TextField(class.getValue()));
stage.setScene(new Scene(parent));// also,
I think, here it should be passed the already opened parent scene
stage.show();
((Node)(event.getSource())).getScene().getWindow().hide();
} });
//這是打開子場景的父場景按鈕的方法
public void add() throws IOException
{
Parent parent = FXMLLoader.load(getClass().getClassLoader().getResource("childStage.fxml"));
stage = new Stage();
stage.initModality(Modality.APPLICATION_MODAL);
stageProdusNou.setScene(new Scene(parent));
stageProdusNou.showAndWait();
}
謝謝。
您可以通過以下方式執行此操作,而無需重新加載基本布局:
這個答案是對這里的代碼和步驟的總結。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.