--- old/modules/javafx.controls/src/main/java/javafx/scene/control/TreeView.java 2017-05-05 11:00:51.000000000 +1200 +++ new/modules/javafx.controls/src/main/java/javafx/scene/control/TreeView.java 2017-05-05 11:00:50.000000000 +1200 @@ -32,6 +32,8 @@ import javafx.application.Platform; import javafx.beans.DefaultProperty; +import javafx.beans.InvalidationListener; +import javafx.beans.WeakInvalidationListener; import javafx.beans.property.BooleanProperty; import javafx.beans.property.DoubleProperty; import javafx.beans.property.ObjectProperty; @@ -336,6 +338,15 @@ MultipleSelectionModel> sm = new TreeViewBitSetSelectionModel(this); setSelectionModel(sm); setFocusModel(new TreeViewFocusModel(this)); + + sceneProperty().addListener((o, oldScene, newScene) -> { + if (oldScene != null) { + oldScene.focusOwnerProperty().removeListener(weakFocusOwnerListener); + } + if (newScene != null) { + newScene.focusOwnerProperty().addListener(weakFocusOwnerListener); + } + }); } @@ -384,6 +395,13 @@ } }; + private InvalidationListener focusOwnerListener = o -> { + if (!ControlUtils.isFocusOnNodeOrAnyChild(this)) { + edit(null); + } + }; + private WeakInvalidationListener weakFocusOwnerListener = new WeakInvalidationListener(focusOwnerListener); + private WeakEventHandler> weakRootEventListener;