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

method java.awt.Component.repaint() doesn't calls update() for some Component

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.0
    • client-libs
    • None
    • sparc
    • solaris_2.5

      This problem has to do with the method java.awt.Component.repaint().

      According to the spec:
      "public void repaint()
            Repaints this component.
            This method causes a call to this component's update method as soon as possible.
      "
      But with the current implemention, the method repaint() doesn't call the update() method for some light weight component.

      See the following code fragment:
      =============================================================
       public Status Component2004() {
          
              Frame fr = new Frame();
              FakeComponent fc = new FakeComponent();
              try {
                  fr.setSize(200, 200);
                  fr.add(fc);
                  fr.setVisible(true);
                  synchronized (fr) {
                      while (!fr.isShowing()) {
                          try {
                              fr.wait(50);
                          } catch (InterruptedException ie) {
                          }
                      }
                  }
                  Graphics g = fc.getGraphics();
                  fc.repaint();
                  synchronized (fr) {
                      while (fc.updateCatch == false) {
                          try {
                              fr.wait(50);
                          } catch (InterruptedException ie) {
                          }
                      }
                  }
                  if (fc.updateCatch == false) {
                      return Status.failed("Failed: method did not call the update() method");
                  }
                  return Status.passed("OKAY");
              } finally {
                  fr.dispose();
              }
          }


          class FakeComponent extends Component {
              public boolean paintCatch = false;
              public boolean updateCatch = false;
              
              public void paint(Graphics g) {
                  paintCatch = true;
                  super.paint(g);
              }
              
              public void update(Graphics g) {
                  updateCatch = true;
                  super.update(g);
              }
          }
        
      ===============================================================================

      The result of running the above code is that it keeps waiting and stays in while loop.

      But if I changed FakeCompoennt extends Canvas instead of Component, the abvoe code passed.






            ssisunw Ssi Ssi (Inactive)
            hji Huafang Ji (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: