Hi,
I wrote code to find a string in a TableView and then select the row or rows containing the string. The code worked as expected. Then I tried to enhance the code to scroll to the first row containing the string. However, when I added the scroll logic, the selected rows did not behave properly.
At times, the wrong rows are selected, and at times, a row that should be selected is not. However, as soon as I click on the tableview the selected rows appear properly. Or, if I mouse over a row that is supposed to be selected, then it becomes selected as I mouse over it.
If I remove the scrollTo call, then the selected rows behave properly. Of course, in this case, I have to click on the tableview to manually scroll to the selected rows, and clicking on the tableview solved the problem anyway. So not sure if this proves anything. However, after removing the scrollTo call, if I manually scroll to the row first, then perform the find, then the selected rows appears properly, so this implies that the scrollTo call is breaking the selection model.
Then I put the scrollTo call back in, then I manually scrolled to the row, then perform the find, and the selected row does not appear. If I mouse over the row, then it appears.
Is this a known defect? Is there a workaround?
This seems to be related to a known defect where the selected row changes when sorting the table columns [RT-21517|http://javafx-jira.kenai.com/browse/RT-21517]. I have this issue as well.
Here's a simplified version of my code. If I remove "tableView.scrollTo(i);", then the selection works. When I add "tableView.scrollTo(i);", then it scrolls to the selected row, but the row is not selected, until I mouse over it, or I click on the tableview. I experimented with tableView.requestFocus() but it did not help. I aslo changed the order of the scrollTo and select methods but that did not help.
Thanks,
Barry
private int findTable(TableView tableView, String find) {
int numRows = tableView.getItems().size();
for (int i=0; i < numRows; i++) {
if (((Alarm) tableView.getItems().get(i)).getDescription().contains(find)) {
tableView.scrollTo(i);
tableView.getSelectionModel().select(i);
return(1);
}
}
return(0);
}
Edited by: 907965 on Jun 10, 2012 10:23 PM