Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8095881

[TableView] incorrect extend selection after inserting items

    XMLWordPrintable

Details

    Description

      Test code:

      import javafx.application.Application;
      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      import javafx.scene.Scene;
      import javafx.scene.control.SelectionMode;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TableView;
      import javafx.scene.control.cell.PropertyValueFactory;
      import javafx.scene.input.KeyCode;
      import javafx.scene.input.KeyEvent;
      import javafx.scene.layout.BorderPane;
      import javafx.stage.Stage;

      import java.util.Locale;
      import java.util.logging.Logger;

      public class TableFocusedCell extends Application {
          private static final Logger LOG = Logger.getLogger(TableFocusedCell.class.getName());

          private final ObservableList<Locale> data = FXCollections.observableArrayList(Locale.getAvailableLocales());

          private final TableView<Locale> table = new TableView<>(data);

          @Override public void start(Stage stage) {
              stage.setTitle("Table FocusedCell Bug");
              // add a listener to see loosing the column
              table.getFocusModel().focusedCellProperty().addListener((p, oldValue, newValue)-> {
                  LOG.info("old/new " + oldValue + "\n " + newValue);
              });
              TableColumn<Locale, String> language = new TableColumn<>("Language");
              language.setCellValueFactory(new PropertyValueFactory<Locale, String>("displayLanguage"));
              TableColumn<Locale, String> country = new TableColumn<>("Country");
              country.setCellValueFactory(new PropertyValueFactory<>("country"));
              table.setItems(data);
              table.getColumns().addAll(language, country);

              table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
              table.addEventFilter(KeyEvent.KEY_PRESSED, e -> {
                  if (e.getCode() == KeyCode.F1) {
                      data.add(0, new Locale("dummy"));
                  }
              });

              Scene scene = new Scene(new BorderPane(table));
              stage.setScene(scene);
              stage.show();
          }

          public static void main(String[] args) {
              launch(args);
          }
      }

      Steps to reproduce:

      - select first row
      - press f1 to insert row at top
      - expected: second row selected and focused
      - actual: second row selected and third row focused [1]
      - press shift-down to extend selection
      - expected: second and third row selected [2]
      - actual: first to fourth row selected

      [1] is the focus-related misbehaviour reported in RT-38477
      [2] looks similar to RT-17735 (reported and fixed against ListView)

      Attachments

        Issue Links

          Activity

            People

              jgiles Jonathan Giles
              fastegal Jeanette Winzenburg
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported: