Below is my tableview,including 3 columns. And each column is binded with one property of Classroom contained by ObservableList 'data'.
List<Classroom> classroomList = DayCare.getClassroomList();
ObservableList<Classroom> data= FXCollections.observableList(classroomList);
classroomIdCol.setCellValueFactory(new PropertyValueFactory<>("id"));
groupIdCol.setCellValueFactory(new PropertyValueFactory<>("groupId"));//This coulum shows the id of groups in each classroom
numberCol.setCellValueFactory(new PropertyValueFactory<>("curPerson"));
tableView.setItems(data);
Now I want to add tooltip only on column groupIdCol and when user put mouse on any cell in this column, the tooltip could show the specfic data of group(s) contained by that cell.I've found one method to add tooltip to certain column:
private void addTooltipToColumnCells(TableColumn<ObservableList<String>, String> column) {
Callback<TableColumn<ObservableList<String>, String>, TableCell<ObservableList<String>, String>> existingCellFactory
= column.getCellFactory();
column.setCellFactory(c -> {
TableCell<ObservableList<String>, String> cell = existingCellFactory.call(c);
Tooltip tooltip = new Tooltip();
tooltip.textProperty().bind(cell.itemProperty());//bind tooltip with property of cell
cell.setTooltip(tooltip);
return cell ;
});
}
However, I have trouble in getting the value of cell.itemProperty(). I need to get the value of each cell in groupId column(which is a String contains groupId) and I'll use the value to search the data of certain groups and then let tooltip to show the data. Is there any method to realize this function? Any help would be appreciated!
Below is my UI,however I could only let tooltip to show data of all groups instead of showing data of certain groups contained by each cell.
Aucun commentaire:
Enregistrer un commentaire