0

In order to provide the correct cell factory or cell factory with correct converter I need to know the cell's value java type. Can't figure out how to access this information, please help

@FXML
private TableColumn<PropertyAndValue, Object> propertyValueColumn;
...
propertyValueColumn.setCellFactory(new Callback<TableColumn<PropertyAndValue, Object>, TableCell<PropertyAndValue, Object>>() {
        @Override
        public TableCell<PropertyAndValue, Object> call(TableColumn<PropertyAndValue, Object> param) {
            Class cellValueClass = ??? // How to get value class ?                
            return new AcceptOnExitTableCell<PropertyAndValue, Object>();
        }
    });
ievgen
  • 1,081
  • 11
  • 20
  • With the code you have, the type is just `Object`. If you want a more specific type, then you would declare the column to have a more specific type. What are you actually displaying in this column? – James_D Jan 17 '17 at 16:32
  • The cell value could be of different data types, Integer, Float and custom objects. I just need to create the proper javafx.util.StringConverter which is by API design not aware of the target value type. – ievgen Jan 17 '17 at 16:52
  • 1
    In that case you can't get it at the point of the code which you have posted. If the cell values for different rows within this same column are different types, then the type of the object shown in any given cell can change *during the lifetime of the cell instance*. Consequently you cannot get the type before construction of the cell. You would need to check the type any time the item displayed by the cell changes: i.e. you need to do that in the cell's `updateItem(...)` method (which you can do easily). – James_D Jan 17 '17 at 16:55
  • Understood, thanks a lot ! – ievgen Jan 17 '17 at 17:58

0 Answers0