문제

I am trying to get the selection from a TableView in JavaFX 2.0. I have stored 5 Persons (5 rows) in the TableView. The code to get the selection model is:

TableView<Person> tableView =
myStage.getTableView();

ObservableList<Person> selection = 
tableView.getSelectionModel().getSelectedItems();

System.out.println(selection.size());

Now when I select multiple rows and then execute the method including the above code, the following prints the selection * 2 and sometimes the selection * 3. For example: I select all 5 rows and it prints out a size of 10 and sometimes 15!

What am I doing wrong here?

도움이 되었습니까?

해결책

There is a bug with TableView returning duplicated items for selection made by shift-click. As a workaround until fix you can try filter duplicated items by:

Set<Person> selection = new HashSet<Person>(tableView.getSelectionModel().getSelectedItems());
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top