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

JScrollbar does not show if JList has large data

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.6.0"
      Java(TM) SE Runtime Environment (build 1.6.0-b105)
      Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)


      ADDITIONAL OS VERSION INFORMATION :
      Linux x86 and Windows XP and Solaris 10

      A DESCRIPTION OF THE PROBLEM :
      The code belows demonstates that when JList contains large dataset, the scrollbar does not appear, although it should.

      Mysterious thing is, that when AMOUNT is set under 125 million, scrollbar reappears and everything works correctly. Also, when AMOUNT is close to Integer.MAX_VALUE, scrollbar is visible but fails to work at larger values.



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the program in description.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      JList and JScrollbar should support lists at least to size Integer.MAX_VALUE as it seems when reading documentation, preferably to any value, of course.
      ACTUAL -
      No scrollbar OR very funnily working list.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;

      public class JListTest
      {
          
          static final int AMOUNT = 128000000; //large list, scrollbar no show
          //static final int AMOUNT = 12000000; //"small" list, scrollbar shows

          static ListModel bigData = new AbstractListModel() {
      public int getSize() { return AMOUNT; }
      public Object getElementAt(int index) { return "Index " + index; }
      };

          public static void main(String[] args) {
      try {
      JFrame f = new JFrame("LIST");

      JList li = new JList(bigData);
      li.setPrototypeCellValue("Index 1234567890");
      JScrollPane p = new JScrollPane(li);
      f.getContentPane().add(p);
      f.setSize(300,300);
      f.setVisible(true);
      } catch (Exception err) {
      err.printStackTrace();
      }
          } // end of main()
      }
      ---------- END SOURCE ----------

            Unassigned Unassigned
            ryeung Roger Yeung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: