从javafx的另一个窗口设置TextField的值

问题描述 投票:0回答:1

我在Action(按Enter)上设置了TextField,以打开另一个fxml窗口,该窗口显示一个选择表(数百个选择)。基本上,我需要第二个窗口在第一个窗口上设置文本字段的文本。

@FXML //this pops out a 2nd window where i can choose a person. Set from Scene Builder
private void pickperson(ActionEvent event) throws IOException {
    Parent parent = FXMLLoader.load(getClass().getResource("/fxml/personpicker.fxml"));
    Scene scene = new Scene(parent);
    Stage stage = new Stage();
    stage.setScene(scene);
    stage.centerOnScreen();
    stage.show();
} 

@FXML //when i click "use selected" this gets executed
private void use(ActionEvent event) {
    Person person0 = table.getSelectionModel().getSelectedItem();
    int id = person0.getId();
    String name = person0.getNAME();
    final Clipboard clipboard = Clipboard.getSystemClipboard();
    final ClipboardContent content = new ClipboardContent();
    content.putString(Integer.toString(id)); //i tried clipboard but when i paste, nothing is pasted
    Stage stage = (Stage) useselected.getScene().getWindow();//closes the window
    stage.close();
}

我在第二个窗口中有一个表,上面有一个按钮,标签为:“使用所选内容”。我要这样做,以便在单击“使用所选内容”时关闭窗口,并同时从所选内容中设置文本字段。

编辑:我通过添加

使剪贴板工作
Clipboard.getSystemClipboard().setContent(content);

现在,我只需要在窗口关闭后直接粘贴值;就像按下CRTL + V一样。

java mysql javafx fxml scenebuilder
1个回答
0
投票

快速,简单的解决方案,在第一个视图上,您​​可以从类中创建一个新对象作为静态变量,并将其分配给下面的代码,如下所示

© www.soinside.com 2019 - 2024. All rights reserved.