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

ListSelectionModel.setSelectionMode() underspecified

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 5.0
    • Fix Version/s: 10
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b31
    • CPU:
      x86
    • OS:
      linux

      Description

      FULL PRODUCT VERSION :
      java version "1.5.0_06"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
      Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_06-b05, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux ubuntu 2.6.12-10-amd64-generic #1 Fri Apr 28 13:18:42 UTC 2006 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      The setSelectionMode() specification doesn't say what happens to the existing selections when changing from a less restrictive mode to a more restrictive mode (for example, from SINGLE_INTERVAL_SELECTION to SINGLE_SELECTION).

      It appears that the current implementation doesn't modify the selections at all, which leaves the model in an inconsistent state. See the example below, where a model ends up in SINGLE_SELECTION mode with two items selected.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See executable test case.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I would expect at most 1 item to remain selected. Or perhaps the change of mode should clear all current selections.
      ACTUAL -
      Item 1 is selected : true
      Item 2 is selected : true
      1.5.0_06


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.DefaultListSelectionModel;
      import javax.swing.ListSelectionModel;

      public class ListSelectionModelTest {

          public static void main(String[] args) {
              System.out.println("Running on: " + System.getProperty("java.version"));
              DefaultListSelectionModel m = new DefaultListSelectionModel();
              m.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
              m.setSelectionInterval(1, 2);
              m.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
              System.out.println("Item 1 is selected : " + m.isSelectedIndex(1));
              System.out.println("Item 2 is selected : " + m.isSelectedIndex(2));
          }
      }

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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              pbansal Pankaj Bansal
              Reporter:
              gmanwanisunw Girish Manwani (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: