【发布时间】:2019-10-05 12:31:11
【问题描述】:
我在 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 一样。
【问题讨论】:
-
当您在第二个
Stage中执行操作时,您不需要使用系统剪贴板来更新一个Stage 中的文本字段的内容。为了向您展示如何做到这一点,如果您发布 minimal reproducible example 会有所帮助。包括 Java 代码和 FXML 文件的内容。 -
@Abra 我希望为时不晚。我制作了我正在尝试做的事情的准系统版本。 github.com/alexislyndon/testcodes
标签: java mysql javafx fxml scenebuilder