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

Slow repaint of JFrame/JLabel

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P1 P1
    • None
    • 1.3.0
    • client-libs
    • None

      The attached program JFrame1.java creates 2000 JLabels, each with a
      blue background, in a JFrame, and then attempts to repaint the backgrounds
      of the JLabels alternately between orange and green every half second.

      The bug is that the JLabels repaint very very slowly in JDK1.3. In
      JDK1.2.2 they repainted slowly, but now it is much much worse. The
      initial transition from blue to orange may take 18 minutes or longer.
      It may then take 8 minutes or more to repaint them from orange to green and
      green to orange. If you don't wait that long, you may conclude it is
      not repainting at all.

      In JDK1.2.2 the initial transition from blue to orange took about 6 seconds
      and the transitions between orange and green took about 3 seconds.

      One problem contributing to this is that in
      src/share/classes/javax/swing/RepaintManager.java
      collectDirtyComponents spends a lot of time in the call to 'contains'
      calling 'indexOf' calling 'equals'.

        java.lang.Object.equals(Object.java)
        java.util.Vector.indexOf(Vector.java)
        java.util.Vector.contains(Vector.java)
        javax.swing.RepaintManager.collectDirtyComponents(RepaintManager.java)
        javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java)

      This is because RepaintManager tries to figure out what needs to be
      repainted as a result of the damage caused by repainting each
      component. Since there are 2000 JLabels in this JFrame, this requires
      at least 2000 squared comparisons. It might be more efficient to change
      the logic so that if most of the JFrame needs to be repainted anyway,
      then don't bother checking for the damage that repainting each
      component causes, but rather repaint the whole frame, thereby avoiding
      all the extra work.

      For example, if the union of the bounding boxes of the components to be
      repainted contains an area greater than 50% of the area of the JFrame,
      then repaint the whole JFrame without checking for damage. Or if the JFrame
      contains more than some large number of components, say 500, then repaint
      the whole JFrame without checking for damage.

      There must be multiple problems contributing to this bug, because even
      with all this extra checking, it does not seem like it should take between
      8 and 18 mimutes to repaint the JLabels.

      mike.bronson@eng 1999-12-10

            sswingtrsunw Swingtraq Swingtraq (Inactive)
            mbronsonsunw Mike Bronson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: