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

JList: Only one ListSelectionEvent fired if list is disabled between events

XMLWordPrintable

      FULL PRODUCT VERSION :
      JDK 1.6.0_02

      ADDITIONAL OS VERSION INFORMATION :
      Windows XPSP2

      A DESCRIPTION OF THE PROBLEM :
      If the JList is disabled between the two events that the ListSelectionListener should receive when selection is changing (i.e. the deselection event with getValueIsAdjusting()=true and the selection event where it is false) the second event is not fired.
      Thus code that acts when the value is not adjusting is never called. The problem is that there are two event listeners - a ListSelectionListener and a MouseListener, and the MouseListener may decide to disable the list and prevents the ListSelectionListener to do its job.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the test code in 1.6.0_02


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      1.4.2 would print
      true
      false
      Code that does something useful
      ACTUAL -
      1.6.0_02 prints
      true

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.JFrame;
      import javax.swing.JList;
      import javax.swing.event.ListSelectionEvent;
      import javax.swing.event.ListSelectionListener;

      public class TestJList {
        public static void main(String[] args) {
          final JList list = new JList(new Object[]{"First", "Second"});
          list.setSelectedIndex(0);
          list.addListSelectionListener(new ListSelectionListener(){
            public void valueChanged(ListSelectionEvent e) {
              System.out.println(e.getValueIsAdjusting());
              if(!e.getValueIsAdjusting()){
                System.out.println("Code that does something useful");
              }
              if(e.getValueIsAdjusting()){
                list.setEnabled(false);
              }
            }
          });

          //Display junk
          JFrame f = new JFrame("TEST");
          f.getContentPane().add(list);
          f.pack();
          f.setLocationRelativeTo(null);
          f.setVisible(true);
        }
      }
      ---------- END SOURCE ----------

      Release Regression From : 5.0u12
      The above release value was the last known release where this
      bug was not reproducible. Since then there has been a regression.

            Unassigned Unassigned
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: