JDK-8189228 : TreeView Multi-Selection does not work properly
  • Type: Bug
  • Component: javafx
  • Sub-Component: controls
  • Affected Version: 8,9,10
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • Submitted: 2017-10-12
  • Updated: 2021-05-05
  • Resolved: 2021-05-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdResolved
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
A TreeView control using SelectionMode.MULTIPLE has many issues.
- The SelectedItems list does not get Remove change notifications in many cases.
- IndexOutOfBoundsException is thrown while changing the selection in some cases
- Clicking the collapse/expand widget changes the selection some cases

Source code for test app attached.

To reproduce:
Under /Root/1 Item1/2 Item 1/3 Item 1
- select "4 Item1"
- multi-select (ctrl- or command- click so '4 Item 1' remains selected) "4 Item 2"
- single-select "4 Item 4"
This results in an IndexOutOfBoundException.

However if you select the first two items in the opposite order  "4 Item 2" + "4 Item 1", then single-select "4 Item 4", no exception is thrown.  However you will notice that the SelectedItems list does not get Remove notifications for the previously selected items.

In fact the only time a Remove change is fired on teh SelectedItems list is when explicitly ctrl-clicking on a selected item to deselect it.  Whenever items are implicitly de-selected due to a new single-selection, there is never an indication that they are removed from the selected items list.

If the collapse widget is toggled for the parent item of selected items, that parent item becomes selected.  However, if none of the child items were selected, toggling the collapse/expand widget does not change the selection.
But, if a parent of the the parent is also selected while child nodes are selected toggling the collapse widget doesn't select the item, and the parent item remains selected. E.g. in the test app select "1 Item 1" under Root, and "4 Item 3" under Root/1 Item 1/2 Item 1/3 Item 1.  Then toggle the collapse widget for "3 Item 1" and see that "1 Item 1" remains selected and "3 Item 1" does not get selected.
Comments
This issue was discussed while fix for JDK-8189354 was being reviewed at https://github.com/openjdk/jfx/pull/480. We identified that the three issues reported in description of this issue are no longer reproducible (even without the fix in PR#480). Also this is a generic issue which describes multiple issues under same JBS, we usually prefer bugs which are specific. We are closing this issue as not reproducible and we shall log a new issue for the NPE(Change.getRemoved() contains null item) mentioned by Scott Palmer in one of the previous comments.
05-05-2021

JDK-8152396 is marked as resolved - but isn't: accidentally fine for the exact example with 2 children, still firing incorrect removed notification for childCount > 2. So re-filed as JDK-8189354
16-10-2017

Reported issues are also observed. 1) The SelectedItems list does not get Remove change notifications in many cases. 2) Clicking the collapse/expand widget changes the selection some cases
13-10-2017

Reported NullPointerExecption (as a second comment by Scott above) is reproducible on 8GA, 9GA, 10ea26 It is not reproducible on JDK - 8u144/8u152
13-10-2017

Reported IndexOutOfBoundsException is reproducible only on 8u144/8u152 It is not reproducible in 8GA, 9GA and 10ea26.
13-10-2017

Java 9 Just toggling a selected item by holding ctrl or command while clicking the same item will result in: Exception in thread "JavaFX Application Thread" java.lang.NullPointerException at example.treeview.Multiselect$1.onChanged(Multiselect.java:29) at javafx.base/com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:164) at javafx.base/com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73) at javafx.base/javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233) at javafx.base/javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482) at javafx.base/javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541) at javafx.base/javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205) at javafx.controls/com.sun.javafx.scene.control.SelectedItemsReadOnlyObservableList.lambda$new$1(SelectedItemsReadOnlyObservableList.java:103) at javafx.base/com.sun.javafx.collections.ListListenerHelper$Generic.fireValueChangedEvent(ListListenerHelper.java:329) at javafx.base/com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73) at javafx.base/javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233) at javafx.base/javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482) at javafx.base/javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541) at javafx.base/javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205) at javafx.controls/com.sun.javafx.scene.control.ReadOnlyUnbackedObservableList._endChange(ReadOnlyUnbackedObservableList.java:63) at javafx.controls/javafx.scene.control.MultipleSelectionModelBase$SelectedIndicesList._endChange(MultipleSelectionModelBase.java:895) at javafx.controls/javafx.scene.control.MultipleSelectionModelBase$SelectedIndicesList.clear(MultipleSelectionModelBase.java:804) at javafx.controls/javafx.scene.control.MultipleSelectionModelBase.clearSelection(MultipleSelectionModelBase.java:551) at javafx.controls/com.sun.javafx.scene.control.behavior.CellBehaviorBase.doSelect(CellBehaviorBase.java:251) at javafx.controls/com.sun.javafx.scene.control.behavior.CellBehaviorBase.mouseReleased(CellBehaviorBase.java:185)
12-10-2017

Found another problem. Watch the change notifications when you do this: select "4 Item 1" add "4 Item 5" add "4 Item 3" Note that the selected item list changes see: Selected Items Changed Added: 4 Item 1 Selected Items Changed Added: 4 Item 5 Selected Items Changed Added: 4 Item 1 A repeat "Add" for "4 Item 1" and nothing for "4 Item 3" -- happens on Java 8, seems to be fixed for Java 9
12-10-2017