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

REGRESSION: ListSelectionEvent.getValueIsAdjusting returns true for JList

    XMLWordPrintable

    Details

      Description

      FULL PRODUCT VERSION :
      java version "1.5.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
      Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      SunOS farhan 5.8 Generic_117350-02 sun4u sparc SUNW,Sun-Blade-1500

      A DESCRIPTION OF THE PROBLEM :
      I have added a JList to a JMenuBar (as a Menu item) in my application.
      Till JDK version 1.4.2_05 everything seems to be fine. As soon as we have
      moved to JDK version 1.5.0, the ListSelectionEvent.getValueIsAdjusting() method
      is always returning true. No matter what you do. Even though I am just clicking
      on one of the item in JList.

      I have compiled and ran the sample code with both JDK1.4.2_05 and JDK1.5.0.
      The results are identified in the Expected and Actual Result areas.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run the sample code provided with this report.
      Once the frame is launched open up the menu called "Menu 1" and click on any
      item from the scrollable panel list.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The label in the previous release 1.4.2_05 returns the following texts:

      ListSelectionEvent.getValueIsAdjusting() -> Returns true
      ListSelectionEvent.getValueIsAdjusting() -> Returns false

      The order is always the same. I believe the first true is for deselecting the
      item and the second is for the new selection.
      ACTUAL -
      Now with JDK1.5.0 the results are the following:

      ListSelectionEvent.getValueIsAdjusting() -> Returns true

      In JDK1.5.0 always returns true.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      No error messages.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import javax.swing.*;
      import javax.swing.event.*;

      public class LSEBug extends JFrame implements ListSelectionListener {

        private JMenuBar menuBar = new JMenuBar();
        private JMenu menu = new JMenu("Menu 1");

        private String[] listItems = {"one", "two", "three", "four", "Exit"};
        private JList list;
        private JLabel label = new JLabel();
        private JScrollPane scrollPane;

        private JMenuItem exitMenuItem;

        public LSEBug() {
          super("ListSelectionEvent Bug");
          list = new JList(listItems);
          list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
          list.setVisibleRowCount(3);
          list.addListSelectionListener(this);
          scrollPane = new JScrollPane(list);

          menu.add(new JMenuItem("Item#1"));
          menu.add(scrollPane);
          menuBar.add(menu);

          getContentPane().add(label);
          setJMenuBar(menuBar);
          setSize(new Dimension(400, 500));
          setVisible(true);
        }

        public void valueChanged(ListSelectionEvent event) {
          if (event.getValueIsAdjusting()) {
            System.out.println("ListSelectionEvent.getValueIsAdjusting() -> Returns tr
      ue");
            label.setText("ListSelectionEvent.getValueIsAdjusting() -> Returns true");
          } else {
            // Never gets executed because ListSelectionEvent.getValueIsAdjusting()
            // always Returns true.
            System.out.println("ListSelectionEvent.getValueIsAdjusting() -> Returns fa
      lse");
            label.setText("ListSelectionEvent.getValueIsAdjusting() -> Returns false")
      ;
          }

          if (list.getSelectedIndex() == 4) {
            System.exit(0);
          }
        }

        public static void main(String[] args) {
          new LSEBug();
        }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      No work around for this method.

      Release Regression From : 1.4.2_07
      The above release value was the last known release where this
      bug was known to work. Since then there has been a regression.
      ###@###.### 2005-06-01 11:47:09 GMT

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              shickeysunw Shannon Hickey (Inactive)
              Reporter:
              ndcosta Nelson Dcosta (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: