I have a TextField set on Action(press enter) to open another fxml window that shows a table of choices(hundreds of choices). Basically I need that 2nd window to set the text of the textfield on the first window.
@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();
}
I have a table on the 2nd window with a button labeled: "use selected". I want to make it so that the moment click "use selected", the window closes and at the same time set the text field from the selection.
Edit: I got the clipboard to work by adding
Clipboard.getSystemClipboard().setContent(content);
Now, I just need to paste the value directly after the window closes; as if CRTL+V was pressed.