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

Tree/TableView: incorrect cell selected after initial navigation into table

    XMLWordPrintable

Details

    Description

      In a table with cell selection, the very first navigation into the table (by key-down) results in selecting the last cell of the first row when it should be the first.

      To reproduce, run the example
      - note that the table is focused (without any default focus in the content, neither row nor cell - bug or feature?)
      - press key-down to move into the table
      - expected: first cell of first row selected
      - actual: last cell of first row selected

      The workaround is to focus the first cell programatically - initially and probably after any change to the data that results in focusModel having nothing focused (not tested, though)

      The example:

      public class TableInitialCellSelection extends Application {

          private Parent createContent() {
              ObservableList<Locale> data = FXCollections.observableArrayList(
                      Arrays.stream(Locale.getAvailableLocales(), 10, 20).collect(Collectors.toList()));
              TableView<Locale> table = new TableView<>(data);
              table.getColumns().addAll(createTableColumn("displayLanguage"), createTableColumn("displayCountry"));
              table.getSelectionModel().setCellSelectionEnabled(true);
              return new BorderPane(table);
          }

          private <T> TableColumn<T, String> createTableColumn(String property) {
              TableColumn<T, String> column = new TableColumn<>(property);
              column.setCellValueFactory(new PropertyValueFactory<>(property));
              return column;
          }

          @Override
          public void start(Stage stage) throws Exception {
              stage.setScene(new Scene(createContent()));
              //stage.setTitle(FXUtils.version());
              stage.show();
          }

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

          @SuppressWarnings("unused")
          private static final Logger LOG = Logger
                  .getLogger(TableInitialCellSelection.class.getName());

      }

      Attachments

        Issue Links

          Activity

            People

              fastegal Jeanette Winzenburg
              fastegal Jeanette Winzenburg
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: