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

java.awt.font.TextLayout.equals() works incorrectly

XMLWordPrintable

    • 2d
    • generic
    • generic

      Platform: All
      JDK: 7, 6

      Class java.awt.font.TextLayout overrides method equals() which says:

          /**
           * Returns <code>true</code> if the specified <code>Object</code> is a
           * <code>TextLayout</code> object and if the specified <code>Object</code>
           * equals this <code>TextLayout</code>.

      In fact it happens only if layouts are the same instance.

      -----------------------------------------------
      import java.awt.*;
      import java.awt.font.*;

      public class Temp {

          public static void main(String[] args) {
              String string = "01234567890123456789";
              Font font = new Font("Helvetica", Font.PLAIN, 12);
              FontRenderContext fontRenderContext = new FontRenderContext(null, true, true);

              TextLayout layout_1 = new TextLayout(string, font, fontRenderContext);
              TextLayout layout_2 = new TextLayout(string, font, fontRenderContext);
              
              boolean areEqual = (layout_1.equals(layout_2));
              System.out.println("areEqual = " + areEqual);
          }
      }
      -----------------------------------------------

            Unassigned Unassigned
            dbessono Dmitry Bessonov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: