I am a newbie in JavaFX and also in java. Guys can you please figure out this code if what is lacking because I can already print the items from the database using the print
The Property Value Factory doesn't match with any getters and setters function in your bean. So if you set the cell value factory as the next:
colID.setCellValueFactory(new PropertyValueFactory<studentInfo, Integer>("id"));
The property value factory will look for the function getId(), setId() and idProperty(). The last one returns the property itself, that you have in your bean. Check the API of PropertyValueFactory and the tutorial of Table View to go deep on this.
Also do what agonist_ says, you are creating a the column twice.
There are a couple things. You are setting the CellValueFactory every time you click on the button. You need to put it in the initialize not in the button event.
And the function getAllstudentInfo() will block your GUI, because the query it's blocking. You should do this in a background thread.
So replace your tblViewer.getItems().setAll(getAllstudentInfo());
to something like:
Service<ObservableList<studentInfo>> service = new Service<ObservableList<studentInfo>>() {
@Override
protected Task<ObservableList<studentInfo>> createTask() {
return new Task<ObservableList<studentInfo>>() {
@Override
protected ObservableList<studentInfo> call() throws Exception {
return FXCollections.observableArrayList(getAllstudentInfo());
}
};
}
};
tblViewer.itemsProperty().bind(service.valueProperty());
service.start();
Take a look on concurrency tutorial of JavaFX 2 sure will help you.
Hope it helps.
Start by not doing new instance on your FXML import. Just
@FXML
private TableColumn<String> colContact;