title: Java Swing JLabel, HTML and custom fonts
body: <p>In our Java Swing application, we're loading a custom font and adding it to a <code>JLabel</code>:</p>
  
  <pre><code>try {
    this.font = Font.createFont(Font.TRUETYPE_FONT, new File("resources/fonts/ourcoolfont.ttf")).deriveFont(16f);
  } catch (Exception e) {
    this.font = new Font("Arial", Font.PLAIN, 16);
  }
  this.label.setFont(this.font);
  </code></pre>
  
  <p>Easy and worked fine on 3 different systems. Until someone else tried to run it. The font was loaded (as we're also using on some other Swing elements), but not used in the <code>JLabel</code>.</p>
  
  <p>After some searching, I've found out you can't use both HTML and a loaded font. For some reasons it works on my system (I assume it has something to do with the Java version), but not on some others. As we would like the project to work in outdated Java versions, just asking to update isn't an option.</p>
  
  <p>One option is to install the font on the computer, something we don't like to do. The best solution I've found is this one:
  <a href="https://stackoverflow.com/questions/456742/how-can-i-create-a-java-swing-text-component-that-is-both-styled-and-has-a-custo">How can I create a Java/Swing text component that is both styled and has a custom font?</a></p>
  
  <p>However, that question is about a <code>JTextPane</code>. A <code>JLabel</code> doesn't seem to have a <code>getStyledDocument()</code> method I can use for that.</p>
  
  <p>Is there any way to let our font work with the <code>JLabel</code>?</p>