我希望实现一个线程,每隔几秒钟运行QueueTabPageController
中的displayQueue
方法,以便在JavaFX GUI上自动更新表视图。目前,GUI中通过手动按下刷新按钮进行更新,但这并不理想。我尝试过一些在此处的示例使用各种方法,但似乎无法正确运行。顺便说一句,我是新手对于线程不太熟悉。任何帮助将不胜感激。
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"));
// display the current queue to screen when opening page each time
displayQueue(Queue.queue);
}
/**
* @param event
* @throws IOException
*/
@FXML
private void btnRefreshQueueClick(ActionEvent event) throws IOException {
displayQueue(Queue.queue);
}
/**
* @param 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);
}
}
感谢您,K