On Tue, 10 Mar 2026 03:00:00 GMT, Ziad El Midaoui <[email protected]> wrote:
>> The bug occurs when `showRoot` is set to false on a root with no children, >> the expanded item count drops is 0 causing `isFocused(0)` to return false >> even though `focusedIndex` is still 0. When items are added afterwards the >> `treeItemListener` sees `focusedIndex=0` and incorrectly shifts it to 1 >> placing the focus on second item of the TreeView. >> The fix replaces `isFocused(0)` with `getFocusedIndex() >= 0`, which reads >> the raw stored index. > > Ziad El Midaoui has updated the pull request incrementally with one > additional commit since the last revision: > > Added Test A few minor changes needed, otherwise looks good. The test fails in master and passes with the fix. tests/system/src/test/java/test/robot/javafx/scene/treeview/TreeViewInitialFocusTest.java line 1: > 1: package test.robot.javafx.scene.treeview; needs the copyright header tests/system/src/test/java/test/robot/javafx/scene/treeview/TreeViewInitialFocusTest.java line 77: > 75: AtomicReference<TreeItem<String>> focusedItem = new > AtomicReference<>(); > 76: AtomicInteger focusedCellCount = new AtomicInteger(-1); > 77: AtomicReference<String> focusedCellText = new AtomicReference<>(); `focusedCellCount` and `focusedCellText` are not used - were you planning to use them in this test? tests/system/src/test/java/test/robot/javafx/scene/treeview/TreeViewInitialFocusTest.java line 99: > 97: focusedCellCount.set(count); > 98: focusedCellText.set(text); > 99: minor: extra newline tests/system/src/test/java/test/robot/javafx/scene/treeview/TreeViewInitialFocusTest.java line 133: > 131: } > 132: } > 133: } minor: missing newline ------------- Changes requested by angorya (Reviewer). PR Review: https://git.openjdk.org/jfx/pull/2095#pullrequestreview-3924193717 PR Review Comment: https://git.openjdk.org/jfx/pull/2095#discussion_r2913654994 PR Review Comment: https://git.openjdk.org/jfx/pull/2095#discussion_r2913660742 PR Review Comment: https://git.openjdk.org/jfx/pull/2095#discussion_r2913359322 PR Review Comment: https://git.openjdk.org/jfx/pull/2095#discussion_r2913360506
