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

[macosx] Certain FontAwesome glyphs don't render in Java Swing JToolBar buttons

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Incomplete
    • Icon: P4 P4
    • tbd
    • 8u20
    • client-libs

      FULL PRODUCT VERSION :
      davids-mbp:web dgilbert$ java -version
      java version "1.8.0_20"
      Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
      Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Darwin davids-mbp 13.3.0 Darwin Kernel Version 13.3.0: Tue Jun 3 21:27:35 PDT 2014; root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      MacBook Pro with retina display

      A DESCRIPTION OF THE PROBLEM :
      I'm using the FontAwesome font file for icons to display in a JToolBar, but certain characters will not display correctly on my Mac with retina display. You can see the problem with screenshots on StackOverflow:

      http://stackoverflow.com/questions/25548143/certain-fontawesome-glyphs-dont-render-in-java-swing-jtoolbar-buttons

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Download the FontAwesome.ttf file (I tried the current version and an older version, both exhibited the same problem). Run this program:

      import java.awt.BorderLayout;
      import java.awt.EventQueue;
      import java.awt.Font;![enter image description here][2]
      import java.awt.FontFormatException;
      import java.io.IOException;
      import java.io.InputStream;
      import javax.swing.JButton;
      import javax.swing.JFrame;
      import javax.swing.JToolBar;

      public class TestFontAwesome {

          public static void main(String[] args) {
              new TestFontAwesome();
          }

          public TestFontAwesome() {
              EventQueue.invokeLater(new Runnable() {
                  @Override
                  public void run() {
                      try (InputStream is = TestFontAwesome.class.getResourceAsStream("/fontawesome-webfont_old.ttf")) {
                          Font font = Font.createFont(Font.TRUETYPE_FONT, is);
                          font = font.deriveFont(Font.PLAIN, 24f);

                          JToolBar toolBar = new JToolBar(JToolBar.VERTICAL);
                          JButton button1 = new JButton("\uf00e");
                          button1.setFont(font);
                          toolBar.add(button1);
                          JButton button2 = new JButton("\uf01e");
                          button2.setFont(font);
                          toolBar.add(button2);
                          JFrame frame = new JFrame("Testing");
                          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                          frame.setLayout(new BorderLayout());
                          frame.add(new JButton("Irrelevant content..."));
                          frame.add(toolBar, BorderLayout.EAST);
                          frame.pack();
                          frame.setLocationRelativeTo(null);
                          frame.setVisible(true);
                      } catch (IOException | FontFormatException exp) {
                          exp.printStackTrace();
                      }
                  }
              });
          }

      }





      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The icon for the first button should show a magnifying glass with a plus symbol.
      ACTUAL -
      The icon for the first button in the toolbar does not display correctly, it shows three empty rectangles.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      import java.awt.BorderLayout;
      import java.awt.EventQueue;
      import java.awt.Font;![enter image description here][2]
      import java.awt.FontFormatException;
      import java.io.IOException;
      import java.io.InputStream;
      import javax.swing.JButton;
      import javax.swing.JFrame;
      import javax.swing.JToolBar;

      public class TestFontAwesome {

          public static void main(String[] args) {
              new TestFontAwesome();
          }

          public TestFontAwesome() {
              EventQueue.invokeLater(new Runnable() {
                  @Override
                  public void run() {
                      try (InputStream is = TestFontAwesome.class.getResourceAsStream("/fontawesome-webfont_old.ttf")) {
                          Font font = Font.createFont(Font.TRUETYPE_FONT, is);
                          font = font.deriveFont(Font.PLAIN, 24f);

                          JToolBar toolBar = new JToolBar(JToolBar.VERTICAL);
                          JButton button1 = new JButton("\uf00e");
                          button1.setFont(font);
                          toolBar.add(button1);
                          JButton button2 = new JButton("\uf01e");
                          button2.setFont(font);
                          toolBar.add(button2);
                          JFrame frame = new JFrame("Testing");
                          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                          frame.setLayout(new BorderLayout());
                          frame.add(new JButton("Irrelevant content..."));
                          frame.add(toolBar, BorderLayout.EAST);
                          frame.pack();
                          frame.setLocationRelativeTo(null);
                          frame.setVisible(true);
                      } catch (IOException | FontFormatException exp) {
                          exp.printStackTrace();
                      }
                  }
              });
          }

      }
      ---------- END SOURCE ----------

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: