JavaFX: Handle ComboBox selection event which is i

2019-02-28 08:18发布

I have a javafx TableView and I want custom controls inside the columns. Say I want a TextField in column1 and ComboBox in column2 and DatePicker in column3.

I know that I should create a class that extends TableCell and override the updateItem() method....

But I read that specifically for this purpose we have default classes like ComboBoxTableCell, TextFieldTableCell etc in the cell package and it is recommended to use them. So I'm able to achieve this with the below code.

loadingStatusTableColumn.setCellFactory(ComboBoxTableCell.forTableColumn("Off", "Load All", "Load By Time"));
startTimeTableColumn.setCellFactory(TextFieldTableCell.forTableColumn(null));
stopTimeTableColumn.setCellFactory(TextFieldTableCell.forTableColumn(null));

Now my requirement is when I select some value from the loadingStatusTableColumn combobox (Say "Off"), I want to disable the next 2 columns startTimeTableColumn, stopTimeTableColumn and they should be enable when I select any value other than "Off" in the loadingStatusTableColumn column.

  1. How to achieve this with my above code(without creating TableCell subclass).

  2. Can i achieve the below line effect through FXML?

    loadingStatusTableColumn.setCellFactory(ComboBoxTableCell.forTableColumn("Off", "Load All", "Load By Time"));
    
    <cellFactory><MyCellFactory /></cellValueFactory>
    

I know the above works because it is a custom class I have, but can I do the below?

<cellFactory><ComboBoxTableCell /></cellValueFactory>

Thanks in Advance!

0条回答
登录 后发表回答