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

JList Keyboard MatchSelection doesnt ensure visibility of selection

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.1
    • client-libs
    • x86
    • windows_2000, windows_xp



      Name: jk109818 Date: 11/14/2002


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

      FULL OPERATING SYSTEM VERSION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      After making a new selection in a JList through typing the
      initials of the items name, the selected item doesnt
      become visible.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Start the swingset2 application tab JFileChooser
      2. Select through typing a non displayed directory
      3. The directory will be selected but not scrolled into
      the visible area

      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER WORKAROUND :
      // Thats not a workaround but a possible patch in file
      // BasicListUI (look for the keyword Patch)

          private static class KeyHandler implements KeyListener
      {

      private String prefix = "";
      private long lastTime = 0L;

      /**
      * Invoked when a key has been typed.
      *
      * Moves the keyboard focus to the first element
      * whose first letter matches the alphanumeric key
      * pressed by the user. Subsequent same key presses
      * move the keyboard focus to the next object that
      * starts with the same letter.
      */
      public void keyTyped(KeyEvent e) {
      JList src = (JList)e.getSource();
      ListModel model = src.getModel();

                  if (model.getSize() == 0 || e.isAltDown() ||
      e.isControlDown() || e.isMetaDown()) {
                      // Nothing to select
                      return;
                  }
      boolean startingFromSelection = true;

      char c = e.getKeyChar();

      long time = e.getWhen();
      int startIndex;
      if (time - lastTime < 1000L && (prefix.length
      () != 1 || c != prefix.charAt(0))) {
      prefix += c;
      startIndex = src.getSelectedIndex();
      } else {
      prefix = "" + c;
      startIndex = src.getSelectedIndex() + 1;
      }
      lastTime = time;

      if (startIndex < 0 || startIndex >=
      model.getSize()) {
      startingFromSelection = false;
      startIndex = 0;
      }
      int index = src.getNextMatch(prefix,
      startIndex,

      Position.Bias.Forward);
      if (index >= 0) {
      src.setSelectedIndex(index);
      // Patch
      src.ensureIndexIsVisible(index);
      // End Patch
      } else if (startingFromSelection) { // wrap
      index = src.getNextMatch(prefix, 0,

      Position.Bias.Forward);
      if (index >= 0) {
      src.setSelectedIndex(index);
      // Patch
      src.ensureIndexIsVisible(index);
      // End Patch
      }
      }
      }

      /**
      * Invoked when a key has been pressed.
      */
      public void keyPressed(KeyEvent e) {
      }

      /**
      * Invoked when a key has been released.
      * See the class description for {@link KeyEvent}
      for a definition of
      * a key released event.
      */
      public void keyReleased(KeyEvent e) {
      }
          }
      (Review ID: 166943)
      ======================================================================

            apikalev Andrey Pikalev
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: