-
Bug
-
Resolution: Unresolved
-
P4
-
jfx11
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());
}
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());
}
- is blocked by
-
JDK-8235491 Tree/TableView: implementation of isSelected(int) violates contract
- Resolved
- relates to
-
JDK-8088012 SelectionModel: mismatches between api doc and implementations
- Open
-
JDK-8088725 TableSelectionModel: missing doc on how cellSelectionEnabled affects behaviour
- Open