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

ListSelectionListener is notified when there was no change to the current selection

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Duplicate
    • Affects Version/s: 6
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:

      Description

      Despite the following assertion:

          "If this represents a change to the current selection, then each ListSelectionListener is notified of the change."

      in method

          JList.public void removeSelectionInterval(int index0, int index1)

      when no change in selection has occured ListSelectionListener is still notified.

      Please look at the following code:

          final JList list = new JList(new Integer[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
          System.out.println("selected indices = " + Arrays.toString(list.getSelectedIndices()));
          
          list.setSelectionInterval(0, 4);
          System.out.println("selected indices = " + Arrays.toString(list.getSelectedIndices()));
          
          list.addListSelectionListener(new ListSelectionListener(){
              public void valueChanged(ListSelectionEvent e) {
                  System.out.println("AddSelectionInterval.valueChanged was called");
                  System.out.println("e.getFirstIndex() = " + e.getFirstIndex());
                  System.out.println("e.getLastIndex() = " + e.getLastIndex());
                  System.out.println("selected indices = " + Arrays.toString(list.getSelectedIndices()));
              }
          });
          list.removeSelectionInterval(7,8);

      It will produce the following output:

      selected indices = []
      selected indices = [0, 1, 2, 3, 4]
      AddSelectionInterval.valueChanged was called
      e.getFirstIndex() = 0
      e.getLastIndex() = 8
      selected indices = [0, 1, 2, 3, 4]

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              shickeysunw Shannon Hickey (Inactive)
              Reporter:
              dbessono Dmitry Bessonov
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: