@@ -352,6 +352,50 @@ public class TableViewTest {
352
352
assertEquals ("Item 2" , fm .getFocusedItem ());
353
353
}
354
354
355
+ @ Test
356
+ public void ensureRowRemainsSelectedWhenSelectingCellInSameRow () {
357
+ class Person {
358
+ final String firstName , lastName ;
359
+ Person (String firstName , String lastName ) {
360
+ this .firstName = firstName ;
361
+ this .lastName = lastName ;
362
+ }
363
+ public String getFirstName () { return firstName ; }
364
+ public String getLastName () { return lastName ; }
365
+ }
366
+
367
+ var tableView = new TableView <Person >();
368
+ tableView .getSelectionModel ().setCellSelectionEnabled (true );
369
+ tableView .getSelectionModel ().setSelectionMode (SelectionMode .MULTIPLE );
370
+
371
+ var col1 = new TableColumn <Person , String >();
372
+ col1 .setCellValueFactory (new PropertyValueFactory <>("firstName" ));
373
+ var col2 = new TableColumn <Person , String >();
374
+ col2 .setCellValueFactory (new PropertyValueFactory <>("lastName" ));
375
+ tableView .getColumns ().addAll (List .of (col1 , col2 ));
376
+
377
+ var ab = new Person ("a" , "b" );
378
+ tableView .getItems ().add (ab );
379
+ var cd = new Person ("c" , "d" );
380
+ tableView .getItems ().add (cd );
381
+
382
+ var selectionModel = tableView .getSelectionModel ();
383
+ selectionModel .select (0 );
384
+ selectionModel .clearAndSelect (0 , col1 );
385
+
386
+ // The following asserts should work once JDK-8273336 is fixed:
387
+ //
388
+ // assertEquals(1, selectionModel.getSelectedIndices().size());
389
+ // assertEquals(0, (int)selectionModel.getSelectedIndices().get(0));
390
+
391
+ selectionModel .clearSelection ();
392
+ selectionModel .selectRange (0 , col1 , 1 , col2 );
393
+ selectionModel .clearAndSelect (1 , col2 );
394
+
395
+ // assertEquals(1, selectionModel.getSelectedIndices().size());
396
+ // assertEquals(1, (int)selectionModel.getSelectedIndices().get(0));
397
+ }
398
+
355
399
/*********************************************************************
356
400
* Tests for columns *
357
401
********************************************************************/
0 commit comments