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

Sometimes TableView cannot select last row after row deletion

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8u40
    • javafx
    • JavaFX 8_40, JDK 8_40 64bit, Windows 7 64 bit, NetBeans 8.0.2

      There seems to be an odd intermittent bug in TableView that makes impossible to select the very last row with the mouse if the row before it has just been deleted. The last row can still be selected with the keyboard though.

      Note: this issue cannot be reproduced all the time.

      Take the following code:

      package tabledelete;

      import javafx.application.Application;
      import javafx.beans.property.SimpleStringProperty;
      import javafx.geometry.Orientation;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.Separator;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TableView;
      import javafx.scene.control.ToolBar;
      import javafx.scene.layout.BorderPane;
      import javafx.stage.Stage;

      public class Test_TableDelete extends Application {

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

          @Override
          public void start(Stage primaryStage) throws Exception {
              final TableView<String> tableView = new TableView();
              tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
              for (int index = 0; index < 10; index++) {
                  final TableColumn<String, String> tableColumn = new TableColumn(String.valueOf(index));
                  tableColumn.setCellValueFactory(param -> {
                      return new SimpleStringProperty(param.getValue());
                  });
                  tableView.getColumns().add(tableColumn);
              }
              final Button populateButton = new Button("Populate");
              populateButton.setOnAction(actionEvent -> populate(tableView));
              final Button deleteButton = new Button("Delete");
              deleteButton.setOnAction(actionEvent -> removeSelected(tableView));
              final ToolBar toolBar = new ToolBar();
              toolBar.getItems().addAll(populateButton, new Separator(Orientation.VERTICAL), deleteButton);
              final BorderPane root = new BorderPane();
      // root.setBottom(tableView);
              root.setCenter(tableView);
              root.setTop(toolBar);
              final Scene scene = new Scene(root);
              primaryStage.setScene(scene);
              primaryStage.show();
              //
              populate(tableView);
          }

          private void populate(final TableView<String> tableView) {
              tableView.getItems().clear();
              for (int value = 0; value < 100; value++) {
                  tableView.getItems().add(String.valueOf(value));
              }
          }

          private void removeSelected(final TableView<String> tableView) {
              final int selectedIndex = tableView.getSelectionModel().getFocusedIndex();
              tableView.getItems().remove(selectedIndex);
          }
      }

      Scroll down fully to the last row.
      Select the row before the last one.
      Click on the Delete button.
      Try to select the last row with the mouse.

      SOMETIMES but not all the time, mouse selection of the last row will not work (even though it may have worked before row deletion).

      Now if you use keyboard to navigate to the last row, you can select it.

            Unassigned Unassigned
            fbouyajfx Fabrice Bouyé (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Imported: