title: Using Custom Fonts [java.io.IOException: Error reading font data.]
body: <p>The title doesn't allow me to say Problem, so the actual error message was -</p>
  
  <pre><code>java.io.IOException: Problem reading font data.
  at java.awt.Font.createFont(Unknown Source)
  at AddFont.createFont(AddFont.java:11)
  at MainFrame$1.run(MainFrame.java:105)
  at java.awt.event.InvocationEvent.dispatch(Unknown Source)
  at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
  at java.awt.EventQueue.access$000(Unknown Source)
  at java.awt.EventQueue$3.run(Unknown Source)
  at java.awt.EventQueue$3.run(Unknown Source)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
  at java.awt.EventQueue.dispatchEvent(Unknown Source)
  at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
  at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
  at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
  at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
  at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
  at java.awt.EventDispatchThread.run(Unknown Source)
  </code></pre>
  
  <p>The code is - </p>
  
  <pre><code>     public static void main(String[] args) {
  javax.swing.SwingUtilities.invokeLater(new Runnable() {
   public void run() {
      try {
          AddFont addFont = new AddFont();
          addFont.createFont();
      } catch (Exception e) {
          e.printStackTrace();
      }
      createGUI();
  
   } //public void run() Closing
  });
  }
  </code></pre>
  
  <p>and the file that I used to get the AddFont addFont-</p>
  
  <pre><code>import java.awt.Font;
  import java.io.BufferedInputStream;
  import java.io.FileInputStream;
  import java.io.InputStream;
  
  
  public class AddFont extends MainFrame{
  public void createFont(){
  Font ttfBase = null;
      Font telegraficoFont = null;{
  try {
      InputStream myStream = new BufferedInputStream(new FileInputStream(FONT_PATH_TELEGRAFICO));
      ttfBase = Font.createFont(Font.TRUETYPE_FONT, myStream);
      telegraficoFont = ttfBase.deriveFont(Font.PLAIN, 24);
  } catch (Exception ex) {
      ex.printStackTrace();
      System.err.println("Font not loaded.");
  }
  }
  }
  }
  </code></pre>
  
  <p>I was instructed to make a new thread because this is a separate problem from my other one. </p>
  
  <p>Why am I getting this problem, and how can I fix it? 
  I have my TELEGRAFICO.TTF font in my imageFolder, which is really just my resources folder. I use </p>
  
  <pre><code>   public static final String FONT_PATH_TELEGRAFICO = "imageFolder/TELEGRAFICO.TTF";
  </code></pre>
  
  <p>to call in my path. </p>
  
  <p>What am I doing wrong?</p>
  
  <p>EDIT - I no longer get that error message, and I don't get "Font not loaded". How can I use the font in other class files other than the one I made that method in?</p>
  
  <p>(I want to use that font on buttons in multiple class files. I tried using it here -</p>
  
  <pre><code>regButton = new JButton();
  regButton.setText("Foo");
  regButton.setAlignmentX(Component.CENTER_ALIGNMENT);
  regButton.setFont(telegraficoFont);
  </code></pre>
  
  <p>But it said telegraficoFont cannot be resolved to a variable. (Because it was in a different class file.)</p>
  
  <p>How can I fix this? Thanks again for the help.</p>