私はTableView
5で持っていTableColumn
ます。これらの列の1つは、マップ上の文化の色を表します。
colorColumn.setCellValueFactory(cellData -> {
return new SimpleObjectProperty<Culture>(cellData.getValue());
});
colorColumn
.setCellFactory(value -> {
CellShape<Rectangle, Culture> elem = new CellShape<Rectangle, Culture>(
new Rectangle(50.0, 30.0, COLOR_OF_APPROPRIATE_CULTURE));
elem.setAlignment(Pos.CENTER);
return elem;
});
ここでCOLOR_OF_APPROPRIATE_CULTURE
-Culture
オブジェクトに設定されているのは色です。
public class Culture
{
private Color color;
//setter and getter
}
では、このカラーフィールドを取得する方法はCellFactory
?
のコールバックはaまたは子孫を返す必要CellShape
があるため、はTableCell
サブクラスであると思います。その場合、メソッドtoを介して行データオブジェクトを取得できます。次のようになります。setCellFactory()
TableCell
getTableRow()
TableCell
myColumn.setCellFactory(new Callback<TableColumn<Data, Fieldtype>, TableCell<Data, Fieldtype>>() {
@Override
public TableCell<Data, Fieldtype> call(TableColumn<Data Fieldtype> param) {
return new TableCell<Data, Fieldtype>(){
@Override
protected void updateItem(Fieldtype item, boolean empty) {
super.updateItem(item, empty);
Object rowDataItem = this.getTableRow().getItem();
// Do what with the row data what you like ...
// ...
}
};
}
});
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加