0

I had this interesting issue come out of QA this morning and other than creating rowfactory for each table - I wanted to see if there was a more straightforward way to accomplish the following.

User double clicks on a record in the table - it launches some behavior. But only do this if they click on an actual row, not the header, or empty space in the table under the rows.

We have this type of code through out our system:

myTable.setOnMouseClicked(event -> {
            if (event.getClickCount() == 2) {
                MyDTO dto = myTable.getSelectionModel().getSelectedItem();
                if(dto != null) {
                    //Do my processing
                }
            }
        });

What our QA tester did was select a row, then double click empty space or the header in the table. This doesn't deselect the record, so the processing fires.

Is there a way to determine at this point if the click happened on a row, or so I need to move my code to a row factory?

purring pigeon
  • 4,141
  • 5
  • 35
  • 68
  • Setting the mouse handler on the `TableRow`s instead of on the table itself is the correct approach. (The more subtle issue with your code is that it makes the assumption that the selection is changed before your event handler is processed. That happens to work, as long as the user is clicking on an actual row, but there's no real guarantee of it. "Selection" and "mouse events" are really two different, if related, things.) – James_D Oct 20 '17 at 17:03
  • Also, I am a bit envious of the quality of your QA team. – James_D Oct 20 '17 at 19:54
  • The QA team is new - we didn't have one before, and now that we have one we are finding all kinds of UI issues :) - I was able to create my own RowFactory and will use that to handle all the logic - so developers will only need to go myTable.setRowFactory(new DoubleClickTableRowFactory(rowData -> {//process selected item})); Thanks again for the help! – purring pigeon Oct 20 '17 at 21:01

0 Answers0