0
私は1つのタイプのオブジェクトの2次元配列を持っています。私はそのデータ、行と列のインデックスに基づいて各テーブルのセルをフォーマットしたい。したがって、私は現在、どのTableViewのセルが現在書式設定中であるかを知る必要があります。 setCellFactory内のupdateItem内に現在のセルインデックスを与えるメソッドを見つけることができませんでした。ここではテーブルビューを作成するための全体のコードは次のとおりです。現在フォーマットされているTableViewセルのインデックスを決定する方法
private TableView<String[]> createTableView() {
String data[][] = { { "a", "b", "c", "d" }, { "f", "f", "h", "h" }, { "i", "a", "k", "a" } };
TableView<String[]> tview = new TableView<String[]>();
ObservableList<String[]> obList = FXCollections.observableArrayList();
for (int i = 0; i < data.length; i++)
obList.add(data[i]);
tview.setItems(obList);
for (int i = 0; i < data[0].length; i++) {
TableColumn<String[], String> col = new TableColumn<String[], String>(data[0][i]);
final int colNo = i;
col.setCellValueFactory(param -> new SimpleStringProperty(param.getValue()[colNo]));
tview.getColumns().add(col);
col.setCellFactory(column -> {
return new TableCell<String[], String>(){
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty) {
int row = getIndex();
int col = 0;//??? how to determine which column is it
setText("["+row+","+col+"] " + item);
}
}
};
});
}
return tview;
}