我有TableView实例,有些列包含ComboBox。
private TableView<ScheduleLecture> tableSchedule;
private TableColumn<ScheduleLecture, DayOfWeek> colDay;
private void initialize() {
colDay.setCellValueFactory(new PropertyValueFactory<>("day"));
colDay.setCellFactory(ComboBoxTableCell.forTableColumn(DayOfWeek.values()));
我需要在关注时扩展TableCell的ComboBox。
public void onTableMouseClicked(MouseEvent event) {
if (tableSchedule.getEditingCell() == null) {
int row = tableSchedule.getSelectionModel().getFocusedIndex();
ObservableList<TablePosition> selectedCells = tableSchedule.getSelectionModel().getSelectedCells();
if(selectedCells.size() == 0){
return;
}
TableColumn col = selectedCells.get(0).getTableColumn();
tableSchedule.edit(row, col);
Object cellData = col.getCellData(0);
if(cellData instanceof Enum){
if(cellData instanceof DayOfWeek){
//comboBox.show(); for cell [row, col.index]
}
}
}
}
我是怎么做到的?
答案 0 :(得分:-1)