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

Font(Map) constructor ignores TextAttribute.FONT field

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 6
    • 2.0
    • client-libs
    • None
    • 2d
    • b33
    • generic
    • generic
    • Verified

      According to the spec of TextAttribute, TextAttribute.FONT is "A way for users to override the resolution of font attributes into a Font, or force use of a particular Font instance".
      Constructor Font(Map) ignores this attribute. See example below:
      ========================= Test57.java =========================
      import java.awt.*;
      import java.util.*;
      import java.awt.font.*;

      public class Test57 {
          public static void main(String[] args) {
              Test57 test = new Test57();
              test.go();
          }

          public void go() {
              Font font = new Font("SomeName", Font.BOLD, 24);

              Hashtable hash = new Hashtable(1);
              hash.put(TextAttribute.FONT, font);

              font = new Font((Map) hash);


              if (!font.getName().equalsIgnoreCase("SomeName")) {
                  System.out.println("getName returned \"" + font.getName() + "\" when \"SomeName\" " +
                              " expected");
              }
              if (font.getStyle() != Font.BOLD) {
                  System.out.println("getStyle returned " + font.getStyle() + " when " +
                              Font.BOLD + " expected");
              }
              if (font.getSize() != 24) {
                  System.out.println("getSize returned " + font.getSize() + " when 24 " +
                              " expected");
              }
              System.out.println("Done");
          }
      }
      ======================= output ====================================
      getName returned "Dialog" when "SomeName" expected
      getStyle returned 0 when 1 expected
      getSize returned 12 when 24 expected
      Done
      ====================================================================
      ###@###.### 10/25/04 16:13 GMT

            dougfelt Doug Felt
            mchernyssunw Michael Chernyshov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: