On Mon, 16 Mar 2026 23:36:03 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:
> 
>   Fix test failing

Marked as reviewed by angorya (Reviewer).

modules/javafx.controls/src/main/java/javafx/scene/control/TreeView.java line 
1675:

> 1673:             showRootListener = obs -> {
> 1674:                 if (getFocusedIndex() >= 0) {
> 1675:                     final int newIndex = treeView.isShowRoot()

we don't need to specify the `final` keyword for effectively final fields.

-------------

PR Review: https://git.openjdk.org/jfx/pull/2095#pullrequestreview-3963111422
PR Review Comment: https://git.openjdk.org/jfx/pull/2095#discussion_r2948967671

Reply via email to