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

Component.isOpaque() works wrong for undisplayable component

XMLWordPrintable

    • beta
    • sparc
    • solaris_2.5



      Name: dsC58869 Date: 03/27/2000


      The method java.awt.Component.isOpaque() works wrong
      for undisplayable component. In this case it returns true,
      but should return false by documentation:
          /**
           * Returns true if this component is completely opaque, returns
           * false by default.
             ^^^^^^^^^^^^^^^^
           * <p>
           * An opaque component paints every pixel within its
           * rectangular region. A non-opaque component paints only some of
           * its pixels, allowing the pixels underneath it to "show through".
           * A component that does not fully paint its pixels therefore
           * provides a degree of transparency. Only lightweight
           * components can be transparent.
           * <p>
           * Subclasses that guarantee to always completely paint their
           * contents should override this method and return true. All
           * of the "heavyweight" AWT components are opaque.
           *
           * @return true if this component is completely opaque.
           * @see #isLightweight
           * @since 1.2
           */

      Here is a minimized test:
      import java.awt.*;

      public class ComponentTest2 {
          public static void main (String[] args) {
              Component c = new StubComponent();
              Frame fr = new Frame();
              System.out.println("Undisplayable Component:");
              if (c.isOpaque()) {
                  System.out.println("FAILED: Componenet is opaque by default");
              } else {
                  System.out.println("OKAY");
              }
              fr.add(c);
              fr.pack();
              while (! fr.isDisplayable()) {
                  Thread.yield();
              }
              System.out.println("Displayable Component:");
              if (c.isOpaque()) {
                  System.out.println("FAILED: Componenet is opaque by default");
              } else {
                  System.out.println("OKAY");
              }
              System.exit(0);
          }
      }
      class StubComponent extends Component {
          public StubComponent() {
              super();
          }
      }

      Output:
      %java -version
      java version "1.3.0rc2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc2-Y)
      Java HotSpot(TM) Client VM (build 1.3.0rc2-Y, interpreted mode)
      %java ComponentTest2
      Undisplayable Component:
      FAILED: Componenet is opaque by default
      Warning:
          Cannot allocate colormap entry for default background
      Displayable Component:
      OKAY

      ======================================================================

            rraysunw Richard Ray (Inactive)
            sdasunw Sda Sda (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: