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

TableView: multiple selection state broken after replace of item

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3 P3
    • tbd
    • 8u131, 9
    • javafx
    • java9-ea-u180

      To reproduce: run the example below and

      - select multiple rows
      - click button to replace an item in the table's item list with a new one
      - expected: selection unchanged
      - actual: selection cleared except the lead selection

      Astonished (by a question on SO - https://stackoverflow.com/q/45915478/203657), I thought the rough edges around data modification and selection had been fixed... add/remove looks okay, just the set is still weird

      The example:

      package test.selection;
      import java.util.Locale;
      import javafx.application.Application;
      import javafx.collections.FXCollections;
      import javafx.scene.Parent;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.SelectionMode;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TableView;
      import javafx.scene.control.cell.PropertyValueFactory;
      import javafx.scene.layout.BorderPane;
      import javafx.scene.layout.HBox;
      import javafx.stage.Stage;

      /**
       * TableView: multiple selection lost on set item.
       */
      public class TableViewMultipleSelectionLostOnSet extends Application {

          private int counter;

          private Parent getContent() {
              TableView<Locale> table = new TableView<>(FXCollections.observableArrayList(
                      Locale.getAvailableLocales()));
              table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
              TableColumn<Locale, String> countryCode = new TableColumn<>("CountryCode");
              countryCode.setCellValueFactory(new PropertyValueFactory<>("country"));
              TableColumn<Locale, String> language = new TableColumn<>("Language");
              language.setCellValueFactory(new PropertyValueFactory<>("language"));
              TableColumn<Locale, String> variant = new TableColumn<>("Variant");
              variant.setCellValueFactory(new PropertyValueFactory<>("variant"));
              table.getColumns().addAll(countryCode, language, variant);
              Button set = new Button("Set");
              set.setOnAction(e -> table.getItems().set(3, new Locale("dummy " + counter++)));
              HBox buttons = new HBox(10, set);
              BorderPane pane = new BorderPane(table);
              pane.setBottom(buttons);
              return pane;
          }

          @Override
          public void start(Stage primaryStage) throws Exception {
              primaryStage.setScene(new Scene(getContent(), 800, 400));
              primaryStage.show();

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

      }


            Unassigned Unassigned
            fastegal Jeanette Winzenburg
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: