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

1.4 REGRESSION: java.awt.Container.add is very slow in Applets

XMLWordPrintable

    • 04
    • x86
    • windows_nt, windows_2000
    • Verified



        Name: jk109818 Date: 09/10/2002


        FULL PRODUCT VERSION :
        java version "1.4.0_01"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
        Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)

        java version "1.4.1-rc"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-rc-b19)
        Java HotSpot(TM) Client VM (build 1.4.1-rc-b19, mixed mode)


        FULL OPERATING SYSTEM VERSION :
        all Windows OS

        A DESCRIPTION OF THE PROBLEM :
        a call to java.awt.Container.add can be very slow (about 3
        seconds or even more) in Applets!


        REGRESSION. Last worked in version 1.3.1

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        1. compile source code
        2. start html-file with the appletviewer
        3. click on the "two" button
          (the center panel will become blue)
        4. click on the "one" button
          it tooks about 3 seconds to switch the panel
          (see output to console)

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        switch of the panels should simply be faster

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        /*
         * Java14test.java 1.0 02/09/10
         */

        import java.awt.*;
        import java.applet.*;
        import java.awt.event.*;

        public class Java14test extends Applet implements ActionListener
        {
          Panel p1 = new Panel();
          Panel p2 = new Panel();
          Panel p3 = new Panel();
          Button b1 = new Button("one");
          Button b2 = new Button("two");
          
          public void init()
          {
            setLayout(new BorderLayout());
            p1.setLayout(new BorderLayout());
            p1.add(BorderLayout.WEST, b1);
            p1.add(BorderLayout.EAST, b2);
            p2.setLayout(null);
            p3.setLayout(null);
            p2.setBackground(Color.yellow);
            p3.setBackground(Color.blue);

            p1.add(BorderLayout.CENTER, p2);
            add(BorderLayout.CENTER, p1);
            b1.addActionListener(this);
            b2.addActionListener(this);
          }

          public void actionPerformed(ActionEvent ae)
          {
            Object obj = ae.getSource();
            if (obj == b1)
            {
              long time1 = System.currentTimeMillis();
              p1.removeAll();
              long time2 = System.currentTimeMillis();
              p1.add(BorderLayout.WEST, b1);
              long time3 = System.currentTimeMillis();
              p1.add(BorderLayout.EAST, b2);
              long time4 = System.currentTimeMillis();
              p1.add(BorderLayout.CENTER, p2);
              long time5 = System.currentTimeMillis();

              invalidate();
              long time6 = System.currentTimeMillis();
              p2.repaint();
              long time7 = System.currentTimeMillis();
              validate();
              long time8 = System.currentTimeMillis();

              System.out.println("<<<<< Change-Status:");
              System.out.println("removeAll: " + (time2-time1)+"ms");
              System.out.println("add button1: " + (time3-time2)+"ms");
              System.out.println("add button2: " + (time4-time3)+"ms");
              System.out.println("add Panel 1: " + (time5-time4)+"ms");
              System.out.println("showing : " + (time8-time5)+"ms");
              System.out.println("all : " + (time8-time1)+"ms");
            }
            else if (obj == b2)
            {
              long time1 = System.currentTimeMillis();
              p1.removeAll();
              long time2 = System.currentTimeMillis();
              p1.add(BorderLayout.WEST, b1);
              long time3 = System.currentTimeMillis();
              p1.add(BorderLayout.EAST, b2);
              long time4 = System.currentTimeMillis();
              p1.add(BorderLayout.CENTER, p3);
              long time5 = System.currentTimeMillis();

              invalidate();
              long time6 = System.currentTimeMillis();
              p3.repaint();
              long time7 = System.currentTimeMillis();
              validate();
              long time8 = System.currentTimeMillis();

              System.out.println("<<<<< Change-Status:");
              System.out.println("removeAll: " + (time2-time1)+"ms");
              System.out.println("add button1: " + (time3-time2)+"ms");
              System.out.println("add button2: " + (time4-time3)+"ms");
              System.out.println("add Panel 2: " + (time5-time4)+"ms");
              System.out.println("showing : " + (time8-time5)+"ms");
              System.out.println("all : " + (time8-time1)+"ms");
            }
          }
        }



        <html>
        <applet code=Java14test.class
            height=150 width=200>
        </applet>
        </html>

        ---------- END SOURCE ----------

        CUSTOMER WORKAROUND :
        use CardLayout instead of removing old panel
        and adding new one

        Release Regression From : 1.3.1_04
        The above release value was the last known release where this
        bug was known to work. Since then there has been a regression.

        (Review ID: 164280)
        ======================================================================

              bino Bino George
              jkimsunw Jeffrey Kim (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: