JDK-6510999 : Selection in a JList with both scrollbars visible jumps on arrowkey-down
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-01-09
  • Updated: 2011-05-18
  • Resolved: 2011-05-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7
6u12Fixed 7 b22Fixed
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.6.0-rc"
Java(TM) SE Runtime Environment (build 1.6.0-rc-b104)
Java HotSpot(TM) Client VM (build 1.6.0-rc-b104, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
pressing arrow-key-down in a jlist with both scrollbars visible,
first visible index > 0 and select index > visible index makes the list
jumping down


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
you can test this with the attached small program.
just be sure to adjust the window to have both scrollbars visible,
scroll down to have the visible index > 0 then scroll up some items
and down again


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
no jumping list
ACTUAL -
jumping list

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

public class JScrollBarTest {

  public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel p = new JPanel(new BorderLayout());
    JList l = new JList();
    DefaultListModel dlm = new DefaultListModel();
    for (int i = 0; i < 100; i++)
      dlm
        .addElement(i
          + " asdjafljasdlfu earp9tuepr9g uepr9t7u " + "wiphdfkjvnasdasdlasdjalsdaksdhaksdhaskjdhaskdhakdhasfkhsadlfh");
    l.setModel(dlm);
    JScrollPane s = new JScrollPane(l);
    l.setSelectedIndex(99);
    l.ensureIndexIsVisible(99);
    p.add(s, BorderLayout.CENTER);
    f.getContentPane().add(p);
    f.pack();
    f.setSize(new Dimension(200, 400));
    f.setVisible(true);
  }

}

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

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

Comments
EVALUATION The problem is in the BasicListUI.Actions.adjustScrollPositionIfNecessary() method it does scrolling only if !visRect.contains(cellBounds) (see it at the beginning of the method) but when the list is too narrow to contain a long item we do vertical scrolling even if there are enough vertical space
20-08-2007

EVALUATION Use these instructions to reproduce: Launch the test. Scroll to the top. Scroll down until item 20 is at the top. Click on item 30. Press the down arrow. Notice how it jumps so that 30 is at the bottom.
12-01-2007

EVALUATION DELETED COMMENT
12-01-2007