I made a Maven JavaFX project + an SQLite database.
Now I can insert succesfully to this database from a form, but I can't show the data inside the TableView. I've followed some tutorials and made a class named ShopDetails:
public class ShopDetails {
private String name;
private String adress;
private String city;
private String state;
private String country;
private String zipcode;
private String phonect;
private String phonearea;
private String phonemain;
}
Added the constructor and the getter-setters. After that I made an ObservableList inside the Controller:
private ObservableList<ShopDetails> data;
private Connection conn = null;
private PreparedStatement pst = null;
private ResultSet rs = null;
and connected to the database inside the initialize method, then I added
data = FXCollections.observableArrayList();
Then I made a method to set the columns which data I want to show used this method:
private void setCellTable(){
columnName.setCellValueFactory(new PropertyValueFactory<>("name"));
//Other columns
}
Any idea how can I solve this problem?
You also need to provide the objecttype from which the field will be fetched
private void setCellTable(){
columnName.setCellValueFactory(new PropertyValueFactory<ShopDetails,String>("name"));
}
In my application I created the table columns myself like
final TableColumn<OSTDataModel, String> taskStatus = new TableColumn<OSTDataModel, String>("Status");
taskStatus.setCellValueFactory(new PropertyValueFactory<OSTDataModel, String>("taskStatus"));
and the class OSTDataModel
was the data structure which was holding my information like your ShopDetails
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.