![](/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.