Why my JavaFX TableView is empty

后端 未结 1 985
野的像风
野的像风 2020-11-28 17:01

I added default TEST1 and TEST2 as Name Col in TableView but didn\'t display when I run it. Here are two classes and one fxml I used for, can anyone give me some advices reg

相关标签:
1条回答
  • 2020-11-28 17:17

    The value you passed to the PropertyValueFactory (rName) does not match the property defined in your model class Table by the get and set method names.

    Since you passed "rName", the PropertyValueFactory will first look for a method called rNameProperty() returning an ObservableValue<String>. Since none exists, it will look for a method getRName() returning a String. Since that doesn't exist either, your have no value to display in the column. (See the Javadocs for a full description.)

    Either change the cell value factory:

    iName.setCellValueFactory(new PropertyValueFactory<Table, String>("name"));
    

    or change the method names in the Table class to getRName() and setRName(...).

    0 讨论(0)
提交回复
热议问题