I have TreeView control with CellFactory:
tVMain.setCellFactory(new Callback<TreeView<ITVItem>, TreeCell<ITVItem>>()
{
@Override
public TreeCell<ITVItem> call(TreeView<ITVItem> p)
{
return new TextFieldTreeCellImpl();
}
});
TextFieldTreeCellImpl:
private static class TextFieldTreeCellImpl extends TextFieldTreeCell<ITVItem>
{
private TextField textField;
public TextFieldTreeCellImpl()
{
this.setOnKeyPressed((e) -> {
startEdit();
});
}
public void startEdit()
{
super.startEdit();
if (textField == null)
{
textField = new TextField();
}
textField.setText(getString());
setText(null);
setGraphic(textField);
textField.selectAll();
textField.requestFocus();
}
@Override
public void cancelEdit()
{
super.cancelEdit();
setText(((ITVItem) getItem()).toString());
setGraphic(getTreeItem().getGraphic());
}
}
The problem is that the OnKeyPressed event never fires. I tried with OnKeyReleased but the result is the same - no event. TextFieldTreeCellImpl also has OnMouseReleased events (not shown in code for brevity) which do work fine.
LAST INFO: When TextFieldTreeCellImpl is in edit mode (startEdit() has been called and textField is visible) the events are triggered. But when the editing is cancelled and the textField removed, events are not firing again.
How can I get the key events to fire in non editing mode?
EDIT: In response to the comment from James_D: I also tried adding
this.addEventFilter(KeyEvent.KEY_PRESSED, e -> {
//SOMETHING
});
instead of OnKeyReleased but that still does not work.