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

Selection state is cleared when you set element to a ListView of size 1

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      generic

      Description

      A DESCRIPTION OF THE PROBLEM :
      States of selection and focus are cleared, when you set element to a ListView of size 1.
      If ListView of size 2 or more, does not occur.
      If initializing with FXCollections.observableArrayList, the error occurs in the second set somehow.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      execute the source code

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      States of selection and focus are not cleared.
      ACTUAL -
      runtime output of source code :
      1-1 selectedIndex : 0, selectedItem : TEST1
      1-1 focusedIndex : 0, focusedItem : TEST1
      1-2 selectedIndex : -1, selectedItem : null
      1-2 focusedIndex : -1, focusedItem : null
      1-3 selectedIndex : -1, selectedItem : null
      1-3 focusedIndex : -1, focusedItem : null

      2-1 selectedIndex : 0, selectedItem : TEST1
      2-1 focusedIndex : 0, focusedItem : TEST1
      2-2 selectedIndex : 0, selectedItem : TEST2
      2-2 focusedIndex : 0, focusedItem : TEST2
      2-3 selectedIndex : 0, selectedItem : TEST3
      2-3 focusedIndex : 0, focusedItem : TEST3

      3-1 selectedIndex : 0, selectedItem : TEST1
      3-1 focusedIndex : 0, focusedItem : TEST1
      3-2 selectedIndex : 0, selectedItem : TEST2
      3-2 focusedIndex : 0, focusedItem : TEST2
      3-3 selectedIndex : -1, selectedItem : null
      3-3 focusedIndex : -1, focusedItem : null

      4-1 selectedIndex : 0, selectedItem : TEST1
      4-1 focusedIndex : 0, focusedItem : TEST1
      4-2 selectedIndex : 0, selectedItem : TEST2
      4-2 focusedIndex : 0, focusedItem : TEST2
      4-3 selectedIndex : 0, selectedItem : TEST3
      4-3 focusedIndex : 0, focusedItem : TEST3

      ---------- BEGIN SOURCE ----------
      import javafx.collections.FXCollections;
      import javafx.fxml.FXML;
      import javafx.fxml.Initializable;
      import javafx.scene.control.ListView;

      import java.net.URL;
      import java.util.ResourceBundle;

      public class Controller implements Initializable {
      @FXML
      private ListView<String> listView1;
      @FXML
      private ListView<String> listView2;
      @FXML
      private ListView<String> listView3;
      @FXML
      private ListView<String> listView4;

      public void initialize(URL location, ResourceBundle resources) {
      // ObservableList, size 1
      listView1.getItems().add("TEST1");
      listView1.getSelectionModel().select(0);
      listView1.getFocusModel().focus(0);
      printLog("1-1", listView1);
      listView1.getItems().set(0, "TEST2");
      printLog("1-2", listView1);
      listView1.getItems().set(0, "TEST3");
      printLog("1-3", listView1);
      System.out.println();

      // ObservableList, size 2
      listView2.getItems().addAll("TEST1", "test1");
      listView2.getSelectionModel().select(0);
      listView2.getFocusModel().focus(0);
      printLog("2-1", listView2);
      listView2.getItems().set(0, "TEST2");
      printLog("2-2", listView2);
      listView2.getItems().set(0, "TEST3");
      printLog("2-3", listView2);
      System.out.println();

      // observableArrayList, size 1
      listView3.setItems(FXCollections.observableArrayList("TEST1"));
      listView3.getSelectionModel().select(0);
      listView3.getFocusModel().focus(0);
      printLog("3-1", listView3);
      listView3.getItems().set(0, "TEST2");
      printLog("3-2", listView3);
      listView3.getItems().set(0, "TEST3");
      printLog("3-3", listView3);
      System.out.println();

      // observableArrayList, size 2
      listView4.setItems(FXCollections.observableArrayList("TEST1", "test1"));
      listView4.getSelectionModel().select(0);
      listView4.getFocusModel().focus(0);
      printLog("4-1", listView4);
      listView4.getItems().set(0, "TEST2");
      printLog("4-2", listView4);
      listView4.getItems().set(0, "TEST3");
      printLog("4-3", listView4);
      System.out.println();
      }

      private void printLog(String label, ListView<String> listView) {
      System.out.println(label + " selectedIndex : " + listView.getSelectionModel().getSelectedIndex() + ", selectedItem : " + listView.getSelectionModel().getSelectedItem());
      System.out.println(label + " focusedIndex : " + listView.getFocusModel().getFocusedIndex() + ", focusedItem : " + listView.getFocusModel().getFocusedItem());
      }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              aghaisas Ajit Ghaisas
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: