繁体   English   中英

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

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

我将Javafx与SceneBuilder一起使用时,我想知道当我们单击按钮时如何在表视图中获取项目或选定行的值(在我的情况下,“编辑按钮”将在另一个窗口的“文本”字段中显示单独的数据)编辑和保存它)我有列(id,名称,姓氏,年龄)对象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");

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM