I want to implement a thread that runs the method displayQueuein QueueTabPageControllerevery couple of seconds to view tables are automatically updated in JavaFX GUI. It is currently being updated manually by clicking the refresh button in the GUI, but this is not ideal. I tried various methods using some examples here, but it doesn't seem to work correctly. By the way, I'm new to streams. Any help would be greatly appreciated.
public class QueueTabPageController implements Initializable {
@FXML
private TableView<Patient> tableView;
@FXML
private TableColumn<Patient, String> firstNameColumn;
@FXML
private TableColumn<Patient, String> lastNameColumn;
@FXML
private TableColumn<Patient, String> timeEnteredColumn;
@FXML
private TableColumn<Patient, String> triageAssessmentColumn;
@FXML
private QueueTabPageController queueTabPageController;
private ObservableList<Patient> tableData;
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
assert tableView != null : "fx:id=\"tableView\" was not injected: check your FXML file 'FXMLQueueTabPage.fxml'";
firstNameColumn.setCellValueFactory(new PropertyValueFactory<Patient, String>("firstName"));
lastNameColumn.setCellValueFactory(new PropertyValueFactory<Patient, String>("lastName"));
timeEnteredColumn.setCellValueFactory(new PropertyValueFactory<Patient, String>("time"));
triageAssessmentColumn.setCellValueFactory(new PropertyValueFactory<Patient, String>("triage"));
displayQueue(Queue.queue);
}
@FXML
private void btnRefreshQueueClick(ActionEvent event) throws IOException {
displayQueue(Queue.queue);
}
public void displayQueue(LinkedList<Patient> queue) {
tableData = FXCollections.observableArrayList(queue);
tableView.setItems(tableData);
tableView.getColumns().get(0).setVisible(false);
tableView.getColumns().get(0).setVisible(true);
}
}
thanks K
source
share