, 당신은 열 '세포 공장 "장식"할 수 있습니다 여기에
private <T> void addTooltipToColumnCells(TableColumn<TableDataType,T> column) {
Callback<TableColumn<TableDataType, T>, TableCell<TableDataType,T>> existingCellFactory
= column.getCellFactory();
column.setCellFactory(c -> {
TableCell<TableDataType, T> cell = existingCellFactory.call(c);
Tooltip tooltip = new Tooltip();
// can use arbitrary binding here to make text depend on cell
// in any way you need:
tooltip.textProperty().bind(cell.itemProperty().asString());
cell.setTooltip(tooltip);
return cell ;
});
}
그냥 당신이 열을 만든 후 지금
TableView<TableDataType> table ;
, 있다고 가정 즉, 당신이 당신의 TableView
를 선언하는 데 사용 어떤 유형 TableDataType
을 대체 테이블에 추가하고, 모든 가전을 설정
for (TableColumn<TableDataType, ?> column : table.getColumns()) {
addTooltipToColumnCells(column);
}
또는 당신이 "자바 (8)"방법을 선호하는 경우 : LL 공장은, 당신은 단지 필요
는 table.getColumns().forEach(this::addTooltipToColumnCells);
이 함께 한 약간의 문제 '가있는이 잘못되고, 빈 셀은 "널 (null)"이 표시이다 매우 우아합니다 (특히 비 기술 사용자의 경우). 이 문제를 극복하는 한 가지 방법은'tooltip' 속성을 셀 상태를 고려한 바인딩에 바인딩하는 것입니다 :'cell.tooltipProperty(). bind (Bindings.when (Bindings.or (cell.emptyProperty(), cell.itemProperty()) .isNull())). then ((툴팁) null) .otherwise (툴팁)); ' – Itai
그냥 내가 뭘 찾고 있었습니까, 고마워요! –