Search code examples
javafxdatepickertableviewtablecelljavafx-tableview

Javafx TableCell When start editing, show old value


I have extended the TableCell class to render a date picker. Its graphic is a javafx.scene.control.DatePicker. I have had to do some onKeyPressed handling to handle tab, enter, and escape, and some other customizations to try to get this TableCell acting in a sane way. Now, when I first select the cell which already contains a value, the DatePicker shows up, but it's blank. It looks like startEdit is being called, but that doesn't provide a value to put into the DatePicker. (https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/TableCell.html)

How do I make the old value of the cell show up in the DatePicker when it first shows up?


Solution

  • Assuming the column type is LocalDate, just call

    datePicker.setValue(getItem());
    

    in the startEdit() method.