如何检测用户点击某个单元格时选择了哪一列(名称或ID)?
答案 0 :(得分:2)
要启用单个单元格而不是整行,请调用
tableView.getSelectionModel().setCellSelectionEnabled(true);
要跟踪选择的单元格,您可以
final ObservableList<TablePosition> selectedCells = table.getSelectionModel().getSelectedCells();
selectedCells.addListener(new ListChangeListener<TablePosition>() {
@Override
public void onChanged(Change change) {
for (TablePosition pos : selectedCells) {
System.out.println("Cell selected in row "+pos.getRow()+" and column "+pos.getColumn().getTitle());
}
});
});