public static void registerBundledFonts() { GraphicsEnvironment grEnv = GraphicsEnvironment.getLocalGraphicsEnvironment(); if (Utils.FONT_HACK != null) { grEnv.registerFont(Utils.FONT_HACK); } }
try { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File("A.ttf"))); } catch (IOException|FontFormatException e) { //Handle exception }
@Signature public static boolean register(PFont font) { GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment(); return e.registerFont(font.getFont()); } }
private static final Font SERIF_FONT = new Font("serif", Font.PLAIN, 24); private static Font getFont(String name) { Font font = null; if (name == null) { return SERIF_FONT; } try { // load from a cache map, if exists if (fonts != null && (font = fonts.get(name)) != null) { return font; } String fName = Params.get().getFontPath() + name; File fontFile = new File(fName); font = Font.createFont(Font.TRUETYPE_FONT, fontFile); GraphicsEnvironment ge = GraphicsEnvironment .getLocalGraphicsEnvironment(); ge.registerFont(font); fonts.put(name, font); } catch (Exception ex) { log.info(name + " not loaded. Using serif font."); font = SERIF_FONT; } return font; }
import java.awt.*; import javax.swing.*; import java.net.URL; class LoadFont { public static void main(String[] args) throws Exception { // This font is < 35Kb. URL fontUrl = new URL("http://www.webpagepublicity.com/" + "free-fonts/a/Airacobra%20Condensed.ttf"); Font font = Font.createFont(Font.TRUETYPE_FONT, fontUrl.openStream()); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); ge.registerFont(font); JList fonts = new JList( ge.getAvailableFontFamilyNames() ); JOptionPane.showMessageDialog(null, new JScrollPane(fonts)); } }
import java.awt.*; import javax.swing.*; import java.net.URL; class DisplayFont { public static void main(String[] args) throws Exception { URL fontUrl = new URL("http://www.webpagepublicity.com/" + "free-fonts/a/Airacobra%20Condensed.ttf"); Font font = Font.createFont(Font.TRUETYPE_FONT, fontUrl.openStream()); font = font.deriveFont(Font.PLAIN,20); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); ge.registerFont(font); JLabel l = new JLabel( "The quick brown fox jumped over the lazy dog. 0123456789"); l.setFont(font); JOptionPane.showMessageDialog(null, l); } }
try (InputStream fontStream = new BufferedInputStream(SwingAppender.class.getResourceAsStream("/com/jsql/view/swing/resources/font/UbuntuMono-R-ctrlchar.ttf"))) { Font ubuntuFont = Font.createFont(Font.TRUETYPE_FONT, fontStream); ge.registerFont(ubuntuFont); } catch (FontFormatException | IOException e) { LOGGER.warn("Loading Font Ubuntu Mono with control characters failed", e); ge.registerFont(ubuntuFont); } catch (FontFormatException | IOException e) { LOGGER.warn("Loading Font Ubuntu failed", e);
GraphicsEnvironment ge = null; try{ ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, game.getClass().getResourceAsStream("/fonts/fantasy.TTF"))); } catch(FontFormatException e){} catch (IOException e){}
try { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File("A.ttf"))); } catch (IOException|FontFormatException e) { //Handle exception }
Font font = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/...")); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); ge.registerFont(font);
Font f = Font.createFont(Font.TRUETYPE_FONT, new File("dvs.ttf")); Font fb = Font.createFont(Font.TRUETYPE_FONT, new File("dvsb.ttf")); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); ge.registerFont(f); ge.registerFont(fb); Font dvs = new Font("DejaVu Sans", Font.PLAIN, 20); Font dvsb = new Font("DejaVu Sans", Font.BOLD, 20);
String filename="path/to/file/whatever.ttf";//this is for testing normally we would store the font file in our app (knows as an embedded resource), see this for help on that http://stackoverflow.com/questions/13796331/jar-embedded-resources-nullpointerexception/13797070#13797070 Font font = Font.createFont(Font.TRUETYPE_FONT, new File(filename)); font = font.deriveFont(Font.BOLD,28); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); ge.registerFont(font); JLabel l = new JLabel("Some Text"); l.setFont(font);
Font font = Font.createFont(Font.TRUETYPE_FONT, getClass().getResource("/CUSTOMFONT-MEDIUM.TTF").openStream()); GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment(); genv.registerFont(font); // makesure to derive the size font = font.deriveFont(12f);
private ImageOverlayBuilder(@NotNull BufferedImage bufferedImage) { this.bufferedImage = bufferedImage; try { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File("src/main/resources/font/notosans/NotoSans-Bold.ttf"))); } catch (IOException | FontFormatException ignored) { } }
/** * A class that contains some useful methods related to the PointOfInterest class and * to general ui related things. */ Util() { try { digitalFont = Font.createFont(0, this.getClass().getResourceAsStream("/eu/hansolo/steelseries/resources/digital.ttf")); GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(digitalFont); } catch (FontFormatException exception) { } catch (java.io.IOException exception) { } }
public static Font createAndRegisterFont(String name) { Font font = null; try { font = Font.createFont(Font.TRUETYPE_FONT, MiscTools.class.getResourceAsStream(name)); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); ge.registerFont(font); } catch (FontFormatException | IOException ex) { Logger.getLogger(MiscTools.class.getName()).log(Level.SEVERE, null, ex); } return font; }
/** * A class that contains some useful methods related to the PointOfInterest class and * to general ui related things. */ Util() { try { digitalFont = Font.createFont(0, this.getClass().getResourceAsStream("/eu/hansolo/steelseries/resources/digital.ttf")); GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(digitalFont); } catch (FontFormatException exception) { } catch (IOException exception) { } }
Font font = Font.createFont(int fontFormat, File fontFile) /(int fontFormat, InputStream fontStream) GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); ge.registerFont(font); if (font.canDisplay()/canDisplayUpTo()){ //your code with font..... }
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); InputStream is = new FileInputStream(new File("path_to_myriad.ttf")); java.awt.Font font; try { font = java.awt.Font.createFont(java.awt.Font.TRUETYPE_FONT, is); ge.registerFont(font); } catch (FontFormatException e) { e.printStackTrace(); }
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); Font font = Font.createFont(Font.TRUETYPE_FONT, ttfFile); ge.registerFont(font); // If you want to load the font. if (pdfFontName.startsWith(font.getFamilyName()) { System.out.printf("%s - %s / %s%n", ttfFile.getName(), font.getFamilyName(), font.getName()); }