Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8304080 | jfx17.0.7 | Johan Vos | P4 | Resolved | Fixed |
With the combination of multiple, cell selection and all cells selected the row is un-/selected for Table-/TreeTableRow (seen in the example below).
Steps to reproduce:
- make sure there is a visible part of the row at the right
- click into a cell of the first column
- extend the selection to the right, such that both columns are selected
- expected: same appearance in Table and TreeTable
- actual: different appearance - for table the row part is not selected,
for TreeTable the row part is selected
The technical reason is the different implementation of updateSelection in the corresponding row:
// tableRow:
selected = !sm.isCellSelectionEnabled() && sm.isSelected(int);
// treeTableRow:
selected = sm.isSelected(int);
The behavior in TableRow seems to be what's expected (there's a code comment to that effect) and TreeTableRow probably should be implemented the same way .. wondering why the different behavior doesn't show up in any test ..
Note: this turned up in review ofJDK-8235491 but is unrelated: same behavior before/after that fix.
Example:
public class SelectionVisuals 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);
table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
TreeTableView<Locale> treeTable = new TreeTableView<>(createTreeData(data));
treeTable.setShowRoot(false);
treeTable.getColumns().addAll(createTreeTableColumn("displayLanguage"), createTreeTableColumn("displayCountry"));
treeTable.getSelectionModel().setCellSelectionEnabled(true);
treeTable.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
HBox compare = new HBox(10, table, treeTable);
BorderPane content = new BorderPane(compare);
return content;
}
private <T> TableColumn<T, String> createTableColumn(String property) {
TableColumn<T, String> column = new TableColumn<>(property);
column.setCellValueFactory(new PropertyValueFactory<>(property));
return column;
}
private TreeItem<Locale> createTreeData(ObservableList<Locale> data) {
TreeItem<Locale> root = new TreeItem<>(Locale.ENGLISH);
ObservableList<TreeItem<Locale>> children = root.getChildren();
data.stream().map(TreeItem::new).forEach(children::add);
return root;
}
private <T> TreeTableColumn<T, String> createTreeTableColumn(String property) {
TreeTableColumn<T, String> column = new TreeTableColumn<>(property);
column.setCellValueFactory(new TreeItemPropertyValueFactory<>(property));
return column;
}
@Override
public void start(Stage stage) throws Exception {
stage.setScene(new Scene(createContent()));
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Steps to reproduce:
- make sure there is a visible part of the row at the right
- click into a cell of the first column
- extend the selection to the right, such that both columns are selected
- expected: same appearance in Table and TreeTable
- actual: different appearance - for table the row part is not selected,
for TreeTable the row part is selected
The technical reason is the different implementation of updateSelection in the corresponding row:
// tableRow:
selected = !sm.isCellSelectionEnabled() && sm.isSelected(int);
// treeTableRow:
selected = sm.isSelected(int);
The behavior in TableRow seems to be what's expected (there's a code comment to that effect) and TreeTableRow probably should be implemented the same way .. wondering why the different behavior doesn't show up in any test ..
Note: this turned up in review of
Example:
public class SelectionVisuals 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);
table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
TreeTableView<Locale> treeTable = new TreeTableView<>(createTreeData(data));
treeTable.setShowRoot(false);
treeTable.getColumns().addAll(createTreeTableColumn("displayLanguage"), createTreeTableColumn("displayCountry"));
treeTable.getSelectionModel().setCellSelectionEnabled(true);
treeTable.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
HBox compare = new HBox(10, table, treeTable);
BorderPane content = new BorderPane(compare);
return content;
}
private <T> TableColumn<T, String> createTableColumn(String property) {
TableColumn<T, String> column = new TableColumn<>(property);
column.setCellValueFactory(new PropertyValueFactory<>(property));
return column;
}
private TreeItem<Locale> createTreeData(ObservableList<Locale> data) {
TreeItem<Locale> root = new TreeItem<>(Locale.ENGLISH);
ObservableList<TreeItem<Locale>> children = root.getChildren();
data.stream().map(TreeItem::new).forEach(children::add);
return root;
}
private <T> TreeTableColumn<T, String> createTreeTableColumn(String property) {
TreeTableColumn<T, String> column = new TreeTableColumn<>(property);
column.setCellValueFactory(new TreeItemPropertyValueFactory<>(property));
return column;
}
@Override
public void start(Stage stage) throws Exception {
stage.setScene(new Scene(createContent()));
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
- backported by
-
JDK-8304080 TableRow vs. TreeTableRow: inconsistent visuals in cell selection mode
- Resolved
- relates to
-
JDK-8235491 Tree/TableView: implementation of isSelected(int) violates contract
- Resolved
-
JDK-8304098 [testbug] Test compilation failure in ControlUtils.java after JDK-8292353
- Resolved
- links to
-
Commit openjdk/jfx17u/4127870e
-
Commit openjdk/jfx/9768b5e4
-
Review openjdk/jfx17u/122
-
Review openjdk/jfx/875
(2 links to)