想象一下,您有一个包含字符串和List的列表视图。我想选择列表视图中的所有字符串,匹配List<String>
,但是,我试图使用SelectionModel中的selectIndices函数,并且正确的整数出来,但它不会选择它们,只有最后一个(与灰色)颜色。我希望他们都有灰色的颜色。JavaFX Listview - 多选编程
一个例子是:
Listview: Cat, Dog, Tiger, Gorilla, Monkey
List: Dog & Gorilla.
选择狗&列表视图中的大猩猩。 selectionMode是'MULTIPLE',SelectionModel是MultipleSelectionModel。
ObservableList<String> names = MainModel.getInstance().getGroupNames();
names.remove(group.getName());
listviewInheritance.setItems(names);
int[] indices = new int[group.getInheritance().size()];
List<String> inheriNames = group.getInheritance();
for(int i = 0; i < inheriNames.size(); i++) {
for(int j = 0; j < names.size(); j++) {
if(inheriNames.get(i).equals(names.get(j))) {
System.out.println("Inheri: " + inheriNames.get(i) + " | Name: " + names.get(j)); // test purpose
indices[i] = j;
}
}
}
if(indices.length > 0) {
System.out.println(Arrays.toString(indices));
listviewInheritance.getSelectionModel().selectIndices(-1, indices);
}
我在想什么?
你尝试过的某些代码可能会帮助人们帮助你 – Rafalon
你是否已将'selectionMode'设置为'MULTIPLE'? – fabian
是的。我可以用我的鼠标和控制按钮选择多行,但我想要编程。 –