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

Bad performance of java.awt.List add/clear

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.1.1
    • client-libs
    • None
    • x86
    • windows_nt



      Name: joT67522 Date: 09/27/97


      1. Compile and run the following.
         Press the button labeled "Insert 100 Lines".
         On my 90MHz Pentium machine this takes about 7 seconds,
         and does a lot of flashing.
         Then press "Clear". For me this takes about 15 seconds.
         You may press "Insert 100 lines" repeatedly to test
         additional insertions.

         This problem is highly correlated to the size of the visible
         part of the List item. It seems to be related to the number
         of repaints. If you resize the frame very small, things
         speed up a lot.



      2. Source code:

      // package perdue.jdktest;

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


      public class ListPerformance extends java.applet.Applet {

        private Button clear = new Button("Clear");
        private Button insert = new Button("Insert 100 Lines");
        private Panel footer = new Panel();
        private List list = new List();

        private int nLines = 0;

        public void init() {
          setLayout(new BorderLayout());
          add("South", footer);
          footer.add(insert);
          footer.add(clear);
          add("Center", list);

          insert.addActionListener(
            new ActionListener()
            {
      public void actionPerformed(ActionEvent e) {
      int limit = nLines+100;
      while (nLines<limit) {
      nLines++;
      list.addItem("Line " + nLines + " welcomes you to the List performance test.");
      }
      }
            }
            );

          clear.addActionListener(
            new ActionListener()
            {
      public void actionPerformed(ActionEvent e) {
      list.removeAll();
      nLines = 0;
      }
            }
            );

        }

        public static void main(String[] args) {
          Frame frame = new Frame("Testing java.awt.List Performance");
          frame.setLayout(new BorderLayout());
          java.applet.Applet applet = new ListPerformance();
          applet.init();
          frame.add("Center", applet);
          frame.setSize(new Dimension(500, 600));
          frame.show();
        }

      }

      company - Rogue Wave Software , email - ###@###.###
      ======================================================================

            msomlosunw Mike Somlo (Inactive)
            johsunw Joon Oh (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: