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

JList.getLastVisibleIndex() can return -1 when in JScrollPane

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P3 P3
    • None
    • 1.2.0
    • client-libs
    • None
    • generic
    • solaris_2.4

      When a JList instance is in a JScrollPane and the JScrollPane viewport is
      taller than the contents of the list, getLastVisibleIndex will return an
      incorrect value of -1. I believe the reason for this is that the logic
      for obtaining the last visible index tries to determine the list row that
      maps to the location at the bottom of the visible rectangle. Since this
      is outside the bounds of the list when the JScrollPane viewport is larger
      than the list, the UI returns a -1 because it assumes an invalid location
      has been sent to it.

      I have attached a small application that places a JList in a JScrollPane.
      At the top of the window is a "Debug" button; when you press it, it
      println's the results of calls to getFirstVisibleIndex, getLastVisibleIndex,
      and getVisibleRowCount. If you resize the application so the JScrollPane
      viewport is smaller than the list, the values are valid. When you resize
      the application so the JScrollPane viewport is larger than the list,
      getLastVisibleIndex is -1.

            sswingtrsunw Swingtraq Swingtraq (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: