0 Replies Latest reply: Oct 23, 2012 4:47 PM by 970275 RSS

    Listening for focus change to perform commitEdit on TableView

    970275
      I'd like to support table cell editing based on focus changes. However, I can't rely on the focus loss because the TableView "steals" the focus momentarily whenever I click on the cell while editing. The example code is the one from Oracle's tutorial at [http://docs.oracle.com/javafx/2/ui_controls/table-view.htm] , Example 13-11 specifically.

      Here's an extract of that example code:
      private void createTextField() {
         textField = new TextField(getString());
         textField.setMinWidth(this.getWidth() - this.getGraphicTextGap()* 2);
         textField.focusedProperty().addListener(new ChangeListener<Boolean>(){
             @Override
             public void changed(ObservableValue<? extends Boolean> arg0, 
                 Boolean arg1, Boolean arg2) {
                     if (!arg2) {
                         commitEdit(textField.getText());
                     }
             }
         });
      }
      When you click on the cell the first time, you enter edit mode. If you click again in the text field, a focus loss event is generated (apparently grabbed by the TableView), which causes the commitEdit to be called prematurely.

      Am I missing something? Is there a workaround for this problem?
      Thanks.