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

tableview wrap in a borderpane, clicked none data row ,selected row was not clear and foucs information was error.

XMLWordPrintable

    • x86
    • other

      FULL PRODUCT VERSION :
      java version "1.8.0_112"
      Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
      Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      when i used a tableview wrap in borderpane, and table data not fulled . tableview will do delete action when double click last column.
      but i selected one row through click this row last cell, no matter where i double click the tableview ,will trigger delete action, have data rows exclude. at such times, i think most coder want to cleared selected rows, when user clicked tableview ,where the row have no data. if not, we will get error information ,from the function <tableView.getFocusModel().getFocusedCell()>

      REGRESSION. Last worked in version 8u112

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :

      Using the code I offered, i hope delete 1 row data ,when double click table last column .
      but double click no data row ,also do delete action, after selected 1 row.
      because the table selectionMode not cleared .when user click no data row, i think most coder want clear selected rows.

      step:
      1. click tablecell ,position = (0,2)
      2. double click no data row, position = (5,1)

      my english is bad, hope you know what i say.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      clear selectionMode. And not trigger delete action.
      ACTUAL -
      triggered delete action

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      ----------------------------------------DeleteTableExample class -------------------------------------------------------------
      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.Alert;
      import javafx.scene.control.Alert.AlertType;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TablePosition;
      import javafx.scene.control.TableView;
      import javafx.scene.control.cell.PropertyValueFactory;
      import javafx.scene.input.MouseButton;
      import javafx.scene.layout.BorderPane;
      import javafx.stage.Stage;

      public class DeleteTableExample extends Application
      {

          @Override
          public void start(Stage primaryStage) throws Exception
          {

              BorderPane borderPane = new BorderPane();

              TableView<Person> tableView = new TableView<>();
              tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
              TableColumn<Person,String> tc1 = new TableColumn<Person,String>("name");
              tc1.setCellValueFactory(new PropertyValueFactory<Person, String>("name"));
              
              TableColumn<Person,String> tc2 = new TableColumn<Person, String>("address");
              tc2.setCellValueFactory(new PropertyValueFactory<Person, String>("address"));
              
              TableColumn<Person,String> tc3 = new TableColumn<Person, String>("delete");
              tableView.getColumns().addAll(tc1, tc2, tc3);

              tableView.getItems().addAll(new Person("name1", "address1"),
                      new Person("name2", "address2"), new Person("name3", "address3"));
              
              tableView.setOnMouseClicked(event->{
                  
                  if(event.getButton()==MouseButton.PRIMARY&&event.getClickCount()==2)
                  {
                      TablePosition pos = tableView.getFocusModel().getFocusedCell();
                      if(pos.getColumn()==2)
                      {
                         new Alert(AlertType.CONFIRMATION, "will delete 1 row data. row number = " +pos.getRow()).showAndWait();
                     //delete action
                      }
                  }
              });

              borderPane.setCenter(tableView);

              Scene scene = new Scene(borderPane);
              primaryStage.setScene(scene);
              primaryStage.setWidth(800);
              primaryStage.setHeight(600);
              primaryStage.show();

          }

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

      }
      -----------------------Person class ------------------------------
      import javafx.beans.property.SimpleStringProperty;

      public class Person
      {
          private SimpleStringProperty name = new SimpleStringProperty();
          private SimpleStringProperty address = new SimpleStringProperty();

          public Person(String name, String address)
          {
              this.name.set(name);
              this.address.set(address);
          }

          public final SimpleStringProperty nameProperty()
          {
              return this.name;
          }

          public final String getName()
          {
              return this.nameProperty().get();
          }

          public final void setName(final String name)
          {
              this.nameProperty().set(name);
          }

          public final SimpleStringProperty addressProperty()
          {
              return this.address;
          }

          public final String getAddress()
          {
              return this.addressProperty().get();
          }

          public final void setAddress(final String address)
          {
              this.addressProperty().set(address);
          }

      }

      ------------------------------------------------------------------
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      TableCellBehaviorBase.class
      protected void doSelect(final double x, final double y, final MouseButton button,
                                final int clickCount, final boolean shiftDown, final boolean shortcutDown){
      .....
         if (tableCell.getIndex() >= count) return;
      ......
      }
      -----------------
      i think before return , need add code
      " this.getSelectionModel().clearSelection();"


      SUPPORT :
      YES

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: