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

ScrollPaneLayout computes wrong and inconsistent preferredSize

XMLWordPrintable

    • x86
    • linux_redhat_9.0

      If you have some smaller content (JPanel with few buttons) and place it into a JScrollPane that is stretched taller by its environment, It would get laid out properly for the first time, but changes its size during next revalidation to include space for (unnecessary) scrollbar.
      This is caused by the fact that initially (during first layout), both extentSize and viewSize are computed based on the preferredSize of the content, but subsequent getPreferredSize calls find viewSize pinned by the previous layout and taller than the content and there seems to be wrong comparison in the ScrollPaneLayout.preferredLayoutSize().

      Worse yet, if you shrink the available space, the properly displays scrollbar, but gets even narrower, so the available area is now 2*scrollbarWidth narrower than initially. Or the layout collapses completly beyond usability (as in the attached example).

      Please try the attached example. It prepares and displays a frame with "right side" prepopulated. It then adds a JScrollPane with small content and it is initially displayed right. Then it schedules a revalidation sequence, that wrongly adjusts the layout.
      (Any external event causing revalidation, like window resize, would cause the same effect.)

      If you shrink the window vertically, it will break for no reason.

      The problem was seen at least in following JDKs: 1.4.0_09, 1.5.0_08, 1.6.0-b71

            Unassigned Unassigned
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: