Multi select in tree on reload

Dear all,
i am facing a challenge in which i hope someone can help me.

I am building a tree interface trough a SQL query, and manipulated by python to create a tree like:

Now this builds fine, the problem arises when i have selected multiple values (it’s used as input for a graph) and i rebuild the tree.

Trough the setSelectedItem() i can set one value/row selected but not multiple. I found some documentation in this forum but they are all regarding Tables, not trees…

Does anyone have any idea on how to script a multi selection on a tree??

You’ll want to use the ‘setSelectionRows()’ method of the underlying tree component. Here is a little code snippet that I set on a button to select a couple items on a default Vision Tree View component.

from javax.swing.tree import TreeSelectionModel

# get the underlying tree component
tree_component = event.source.parent.getComponent('Tree View').getComponent(0).getComponent(0)

#set our selection model to allow discontiguous selection (e.g., select rows 1 and 3 but not 2)

# the rows we want to select
selected_rows = [2,4]

# now apply the selection to the component

You’ll just need to work your selection logic into populating a list like ‘selection_rows’. Hope this helps!