I have implemented a custom datePickerTableCell to show a date picker on cell edit. I am using the ExtFX DatePicker (https://bitbucket.org/sco0ter/extfx/overview). Everything works fine except when I enter the date manually instead of choosing it from picker, I get a NullPointerException on commitEdit().
datePicker.setOnKeyPressed(new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent t) {
if (t.getCode() == KeyCode.ENTER) {
if(getItem() == null) {
commitEdit(null);
} else {
commitEdit(getItem());
}
} else if (t.getCode() == KeyCode.ESCAPE) {
cancelEdit();
}
}
});
I coudnt find whats going wrong here.
This example may help too. It uses a DatePicker and TableView control with Java 8.
I faced a similar issue when using a
TextArea
as table cells. The issue turns out to be I was usingstartEdit
in theTableCell
implementation. UsingTableView#edit
instead ofstartEdit
resolved the issue.Maybe have a look at this example. It uses a color picker but works as well for a date picker:
If you're on Java 7, replace the lambdas with anonymous inner classes, but it should work as well. Full blog post is here.
See if this example helps. It uses Java 8 and the DatePicker control from there.