0

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.

Nitkov
  • 468
  • 6
  • 18
  • `TextField`s typically consume the key events they process. Try adding an event filter instead: `this.addEventFilter(KeyEvent.KEY_PRESSED, e -> { /* something */});` – James_D Dec 03 '15 at 13:35
  • 1
    keyevents are delivered to the focused node (aka: focusOwner of scene) - that's never the cell, but either the textField (while editing) or the table (while not editing). Some more info: http://stackoverflow.com/q/28673753/203657 – kleopatra Dec 03 '15 at 15:55

0 Answers0