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

Clicking different columns (cells) of a selected row in a TableView sets the selected item to NULL

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Duplicate
    • Affects Version/s: 8u40
    • Fix Version/s: 8u40
    • Component/s: javafx
    • Labels:
    • Environment:

      java version "1.8.0_40-ea"
      Java(TM) SE Runtime Environment (build 1.8.0_40-ea-b15)
      Java HotSpot(TM) 64-Bit Server VM (build 25.40-b18, mixed mode)

      Microsoft Windows [Version 6.1.7601]

      Description

      Issue:

      When you select a table row, and then further click inside the selected row but in a different column (so you're selecting a different cell, basically click back and forth between the two columns in the test case but within the selected row), the SelectedItem gets set to null.

      Code to reproduce:

      import javafx.application.Application;
      import javafx.application.Platform;
      import javafx.beans.property.SimpleStringProperty;
      import javafx.beans.property.StringProperty;
      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      import javafx.scene.Scene;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TableView;
      import javafx.scene.control.cell.PropertyValueFactory;
      import javafx.stage.Stage;

      public class TableSelectionBug extends Application {

      @Override
      public void start(final Stage stage) throws Exception {
      TableView<OneRow> table = new TableView<OneRow>();
      table.getSelectionModel().setCellSelectionEnabled(false);
      table.setEditable(false);

      table.getSelectionModel().selectedItemProperty().addListener((prop, ov, nv)-> System.out.println("Selected item is: " + nv));

      final ObservableList<OneRow> tableData = FXCollections.synchronizedObservableList(FXCollections.observableArrayList());
      for (int i = 0; i < 30; i++) {
      tableData.add(new OneRow("Name #" + i, "Surname #" + i));
      }

      TableColumn<OneRow, String> col1 = new TableColumn<OneRow, String>("First Name");
      col1.setCellValueFactory(new PropertyValueFactory<OneRow, String>("firstName"));
      TableColumn<OneRow, String> col2 = new TableColumn<OneRow, String>("Last Name");
      col2.setCellValueFactory(new PropertyValueFactory<OneRow, String>("lastName"));

      table.setItems(tableData);
      table.getColumns().add(col1);
      table.getColumns().add(col2);

      Scene mainScene = new Scene(table, 800, 600);
      stage.setScene(mainScene);

      stage.setTitle("Select a row in the table, then click around on different columns within the row.");
      stage.show();

      stage.setOnCloseRequest(e -> {
      Platform.exit();
      System.exit(0);
      });

      }

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

      public class OneRow {

      public OneRow(String firstName, String lastName) {
      setFirstName(firstName);
      setLastName(lastName);
      }

      private StringProperty _firstNameProperty;

      private StringProperty _lastNameProperty;

      public StringProperty firstNameProperty() {
      if (_firstNameProperty == null) {
      _firstNameProperty = new SimpleStringProperty();
      }

      return _firstNameProperty;
      }

      public void setFirstName(String firstName) {
      firstNameProperty().set(firstName);
      }

      public String getFirstName() {
      return firstNameProperty().get();
      }

      public StringProperty lastNameProperty() {
      if (_lastNameProperty == null) {
      _lastNameProperty = new SimpleStringProperty();
      }

      return _lastNameProperty;
      }

      public void setLastName(String lastName) {
      lastNameProperty().set(lastName);
      }

      public String getLastName() {
      return lastNameProperty().get();
      }

      }
      }

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jgiles Jonathan Giles
              Reporter:
              ecrumhornjfx Emil Crumhorn (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported: