、あなたはカラムの細胞工場「飾る」ことができます。ここでは
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
を交換表に追加して、すべてのCEを設定しますLLの工場は、あなただけの必要があります。
for (TableColumn<TableDataType, ?> column : table.getColumns()) {
addTooltipToColumnCells(column);
}
か、「Javaの8」の方法を好む場合:これで
table.getColumns().forEach(this::addTooltipToColumnCells);
一つ若干の問題は、それがにISNれ、空のセルのための「ヌル」を示すことです非常に優雅です(特に技術者以外のユーザーの場合)。これを克服する1つの方法は、 'tooltip'プロパティを、セルステータスを考慮に入れたバインディングにバインドすることです:' cell.tooltipProperty()。bind(Bindings.when(Bindings.or(cell.emptyProperty()、cell.itemProperty() ).isNull()))。then((ツールチップ)null).otherwise(ツールチップ)); ' – Itai
私が探していたもの、ありがとう! –