JDK-4457325 : JList setSelectedValue(value, true) does not scroll
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.3.1,1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic,solaris_8
  • CPU: generic,sparc
  • Submitted: 2001-05-10
  • Updated: 2001-06-19
  • Resolved: 2001-06-19
Related Reports
Duplicate :  
Duplicate :  
Description

Name: bsC130419			Date: 05/10/2001


java version "1.3.1-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-beta-b15)
Java HotSpot(TM) Client VM (build 1.3.1beta-b15, interpreted mode)


JList does not scroll to selected item for setSelectedValue(value, true), but
the item is selected, as can be seen if the user scrolls manually.  The attached
code works correctly run under 1.2.2, but does not scroll under 1.3.0 or 1.3.1.

import java.awt.*;
import javax.swing.*;

public class JListBug {

   public static void main(String args[]) {

      JFrame        jFrame      = new JFrame();
      JPanel        jPanel      = new JPanel();
      JScrollPane   jScrollPane;

      String[] names = { "aaaaa", "bbbbb", "ccccc", "ddddd", "eeeee", "fffff",
                         "ggggg", "hhhhh", "iiiii", "jjjjj", "kkkkk", "lllll",
                         "mmmmm", "nnnnn", "ooooo", "ppppp", "qqqqq", "rrrrr",
                         "sssss", "ttttt", "uuuuu", "vvvvv", "wwwww", "xxxxx",
                         "yyyyy", "zzzzz" };

      JList jList = new JList(names);
      jScrollPane = new JScrollPane(jList);

      jPanel.setLayout(new GridBagLayout());
      jPanel.add(jScrollPane,
                 new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
                                        GridBagConstraints.CENTER,
                                        GridBagConstraints.NONE,
                                        new Insets(0, 0, 0, 0),
                                        0, 0));

      jList.setSelectedValue("xxxxx", true);      // <---<< Neither of these
      jList.ensureIndexIsVisible(23);             // <---<<  work under 1.3.0

      jFrame.getContentPane().add(jPanel);
      jFrame.pack();
      jFrame.setVisible(true);
   }
}
(Review ID: 124124) 
======================================================================

Comments
WORK AROUND Name: bsC130419 Date: 05/10/2001 SwingUtilities.invokeLater(new Runnable() { public void run() { setSelection(); } } ); works, but it is not possible to pass variable parameters, only final or constant values, to the invoked method. ======================================================================
11-06-2004

EVALUATION This is a duplicate of 4337516, which is fixed for merlin. Refer to if for more information. scott.violet@eng 2001-06-19
19-06-2001