2017-08-25 99 views
0

我有TableView實例和一些列包含ComboBoxes。如何從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組合框。

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] 
      } 
     } 
    } 
} 

我該怎麼做?

回答