JavaFx getSelectedRow 和 GetSelectedItem 来自 TableView 并获取单独变量中列的值

JavaFx getSelectedRow and GetSelectedItem from TableView and get the value of the columns in separate variabls

我正在将 Javafx 与 SceneBuilder 一起使用 我想知道当我们单击按钮(在我的例子中是编辑按钮 hwo 显示在另一个 window 中将文本字段中的数据分开以对其进行编辑并保存) 我有列( id , name , surname , age )对象 Student 。 这是我的按钮操作

try {                   
    FXMLLoader loader = new FXMLLoader();
    Pane root = loader.load(getClass().getResource("/application/Ajout.fxml").openStream());
    AjoutController ajoutcontroller = (AjoutController)loader.getController();

    // recupérer men la table les elements hna  we n7otohom fe nameR we surnameR we ageR
    table.getSelectionModel().getSelectedItems();
    nameR = table.getItems(); // from the table view element in column name to the variable nameR 

    ajoutcontroller.GetStudentDetail(nameR, surnameR, ageR);
    Scene scene = new Scene(root);
    Stage primaryStage= new Stage();
    primaryStage.setScene(scene);
    primaryStage.show();
} catch(IOException e) {

}

对于任何需要它的人

 Student stud = table.getSelectionModel().getSelectedItem();

    String nameR = stud.getName();
    String surnameR = stud.getSurname();
    String ageR = stud.getAge().toString();

而在税字段所在的其他场景中,您只需放置此函数

 public void GetStudentDetail(String nameR, String surnameR, String ageR){

    nametf.setText(nameR);
    surnametf.setText(surnameR);
    agetf.setText(ageR);
    btnajout.setText("Save");

}