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

fp.bugs 3439 Win32 Frame's "validate" method is called spuriously

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.1
    • 1.0
    • client-libs
    • 1.1
    • sparc
    • solaris_2.5
    • Not verified

      >From: ###@###.### (Doug Stein)
       
      Category: AWT

      Priority: Low (Low/Medium/High/Critical)

      JDK version: JDK-1_0-win32-x86.exe

      Platforms: Windows 95 [Version 4.00.950]
      Windows NT version 3.51

      Synopsis
      --------

      Frame's "validate" method is called spuriously on Windows.


      Description
      -----------

      This bug occurs on Windows95 and WindowsNT.

      When the top level frame is resized, "validate" is called many more times
      than necessary. The number of times appears to be related to the number
      of children contained by the frame.


      Test Case
      ---------

      - Compile and run validate.java:

      javac validate.java
      java validate

      - Resize the window

        The "validate" method on the frame is called 13 times. One call to
        validate would suffice.

        
      ----------
      X-Sun-Data-Type: default
      X-Sun-Data-Description: default
      X-Sun-Data-Name: validate.java
      X-Sun-Charset: us-ascii
      X-Sun-Content-Lines: 83


      import java.awt.*;

      class BorderPanel extends Panel {
        private static final int borderWidth = 10;

        public Dimension minimumSize() {
          Dimension d;

          if (countComponents() > 0) {
            Component comp = getComponent(0);
            d = comp.minimumSize();
          }
          else {
            d = new Dimension(0, 0);
          }

          d.width += 2*borderWidth;
          d.height += 2*borderWidth;

          return d;
        }

        public Dimension preferredSize() {
          return minimumSize();
        }

        public void layout() {
          Dimension d = size();
          Component components[] = getComponents();

          for (int i=0; i<components.length; i++) {
            if (i==0) {
      components[i].reshape(borderWidth, borderWidth,
      d.width - 2*borderWidth,
      d.height - 2*borderWidth);
            }
            else {
      components[i].reshape(-1, -1, 0, 0);
            }
          }
        }

        public void paint(Graphics g) {
          Dimension d = size();
          g.drawRect(0, 0, d.width-1, d.height-1);
          g.drawRect(1, 1, d.width-3, d.height-3);
        }
      }

      public class validate extends Frame {
        private int validateCount;

        public static void main(String argv[]) {
          new validate();
        }

        public validate() {
          Button button = new Button("Button");
          Panel p = new BorderPanel();
          createNestedPanels(button, p, 10);
          add("Center", p);

          show();
          resize(preferredSize());
          validate();
        }

        public void createNestedPanels(Component c, Panel parent, int num) {
          if (num == 0)
            parent.add(c);
          else {
            Panel bp = new BorderPanel();
            parent.add(bp);
            createNestedPanels(c, bp, num-1);
          }
        }

        public void validate() {
          super.validate();
          System.out.println("validate " + validateCount++);
        }
      }


            tballsunw Tom Ball (Inactive)
            bhagen Benjamin Hagen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: