Advertisement
StormWingDelta

Java Font Loading Class

May 26th, 2012
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. Still needs some work on making it easier to load fonts but it works for me. :D
  2. Changed out the file path that was there for a fake one.  Put in one of your choosing.
  3.  
  4. public static void FontTester()
  5.     {
  6.         try
  7.         {
  8.             Font f = Font.createFont(Font.TRUETYPE_FONT, new FileInputStream(new File("File\\path\\to\\font\\filename"))).deriveFont(Font.PLAIN, 75);
  9.             JLabel testLabel = new JLabel ("Looky Me I can Load Fonts In Java \"" + f.getName() + "\"");
  10.             testLabel.setFont (f);
  11.             JFrame frame = new JFrame ("Font Loading Demo");  
  12.             frame.getContentPane().add (testLabel);
  13.             frame.pack(); frame.setVisible(true);
  14.         }
  15.         catch(Exception e)
  16.         {
  17.             e.printStackTrace();
  18.         }
  19.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement