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 inRT-38477
[2] looks similar toRT-17735 (reported and fixed against ListView)
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
[2] looks similar to
- duplicates
-
JDK-8096817 TableView: first row focused after first insert of item
- Closed