On Mon, 6 Dec 2021 13:05:16 GMT, Jeanette Winzenburg <faste...@openjdk.org> wrote:
> might also need a test that verifies the focusWithin of a parent added > somewhere above the focused node? hmm .. or maybe not, that would require to > re-arrange a complete subtree .. Inserting a parent into a scene graph such that the existing subtree at that position becomes a subtree of the newly inserted parent can't be done as an atomic operation. First, you'll need to remove the subtree at the insertion point from the existing scene graph (otherwise you'll get an exception saying that a node can only appear once in a scene graph). Then you can add the new parent with the removed subtree as its child. But what happens if the removed subtree contains a focused node? Since we can't know whether the removed subtree will ever be re-attached to the scene graph, we probably shouldn't keep its focus flags set. Moreover, `Scene.focusOwner` probably also should not refer to a node that is not part of the scene graph anymore. But that's not what happens: // Create a focusable rect var rect = new Rectangle(); rect.setFocusTraversable(true); // Add the rect to a group and requestFocus on the rect var root = new Group(rect); scene.setRoot(root); rect.requestFocus(); // Now, the rect is focused and it is the focus owner of the scene assertTrue(rect.isFocused()); assertSame(rect, scene.getFocusOwner()); // Remove the rect from the scene graph root.getChildren().clear(); // This is what I would now assume to be true (but isn't): assertFalse(rect.isFocused()); // FAILED: rect.isFocused() == true assertNotSame(rect, scene.getFocusOwner()); // FAILED: rect == scene.getFocusOwner() I'm inclined to think that this behavior is a bug. ------------- PR: https://git.openjdk.java.net/jfx/pull/475