List of usage examples for java.awt Font getName
public String getName()
From source file:Main.java
public static void main(String[] args) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); Font[] fonts = ge.getAllFonts(); for (Font font : fonts) { String fontName = font.getName(); String familyName = font.getFamily(); System.out.println("Font: " + fontName + "; family: " + familyName); }/*from w w w . j a v a 2 s. com*/ }
From source file:Main.java
public static void main(String[] args) { final StringBuilder sb = new StringBuilder(); sb.append("<html>"); sb.append("<body><ol>"); Font[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts(); for (Font font : fonts) { String name = font.getName(); sb.append("<li style='font-family: " + name + "; font-size: 20px;'>"); sb.append(name);/* www. j a v a2 s . c o m*/ } JScrollPane sp = new JScrollPane(new JLabel(sb.toString())); Dimension d = sp.getPreferredSize(); sp.setPreferredSize(new Dimension(d.width, 150)); JOptionPane.showMessageDialog(null, sp); }
From source file:Main.java
public static void main(String[] args) throws Exception { File f = new File("your.ttf"); FileInputStream in = new FileInputStream(f); Font dynamicFont = Font.createFont(Font.TRUETYPE_FONT, in); Font dynamicFont32Pt = dynamicFont.deriveFont(32f); JLabel testLabel = new JLabel(dynamicFont.getName()); testLabel.setFont(dynamicFont32Pt);/*from ww w . ja v a 2 s . c o m*/ JFrame frame = new JFrame("Font Loading Demo"); frame.getContentPane().add(testLabel); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { File f = new File("your.ttf"); FileInputStream in = new FileInputStream(f); Font dynamicFont = Font.createFont(Font.TRUETYPE_FONT, in); Font dynamicFont32Pt = dynamicFont.deriveFont(32f); JLabel testLabel = new JLabel("Dynamically loaded font \"" + dynamicFont.getName() + "\""); testLabel.setFont(dynamicFont32Pt);/* w ww . ja va2 s . co m*/ JFrame frame = new JFrame("Font Loading Demo"); frame.getContentPane().add(testLabel); frame.pack(); frame.setVisible(true); }
From source file:uk.co.modularaudio.componentdesigner.ComponentDesignerLauncher.java
public static void main(final String[] args) throws Exception { FontResetter.turnOnGlobalAaText();//from w ww . j a va2s .co m boolean useSystemLookAndFeel = false; boolean showAlpha = false; boolean showBeta = false; String additionalBeansResource = null; String additionalConfigResource = null; String configResourcePath = CDCONFIG_PROPERTIES; if (args.length > 0) { for (int i = 0; i < args.length; ++i) { final String arg = args[i]; if (arg.equals("--useSlaf")) { useSystemLookAndFeel = true; } else if (arg.equals("--beta")) { showBeta = true; } else if (arg.equals("--alpha")) { showAlpha = true; showBeta = true; } else if (arg.equals("--pluginJar")) { additionalBeansResource = PLUGIN_BEANS_RESOURCE_PATH; additionalConfigResource = PLUGIN_CONFIG_RESOURCE_PATH; if (log.isDebugEnabled()) { log.debug("Will append plugin beans: " + additionalBeansResource); log.debug("Will append plugin config file: " + additionalConfigResource); } } else if (arg.equals("--development")) { // Let me specify certain things with hard paths configResourcePath = CDDEVELOPMENT_PROPERTIES; log.info("In development mode. Will use development properties for configuration"); } else if (arg.equals("--jprofiler")) { configResourcePath = CDJPROFILER_PROPERTIES; log.info("In jprofiler mode - using jprofiler properties for configuration"); } else { final String msg = "Unknown command line argument: " + arg; log.error(msg); throw new DatastoreException(msg); } } if (useSystemLookAndFeel) { log.info("System look and feel activated"); } if (showAlpha) { log.info("Showing alpha components"); } if (showBeta) { log.info("Showing beta components"); } } if (useSystemLookAndFeel) { final String gtkLookAndFeelClassName = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel"; boolean foundGtkLaf = false; final LookAndFeelInfo lafis[] = UIManager.getInstalledLookAndFeels(); for (final LookAndFeelInfo lafi : lafis) { final String lc = lafi.getClassName(); if (lc.equals(gtkLookAndFeelClassName)) { foundGtkLaf = true; break; } } if (foundGtkLaf) { log.debug("Found available GTK laf. Will set active"); UIManager.setLookAndFeel(gtkLookAndFeelClassName); } UIManager.put("Slider.paintValue", Boolean.FALSE); } final Font f = Font.decode(""); final String fontName = f.getName(); FontResetter.setUIFontFromString(fontName, Font.PLAIN, 10); log.debug("ComponentDesigner starting."); // Set the fft library to only use current thread JTransformsConfigurator.setThreadsToOne(); final ComponentDesignerLauncher application = new ComponentDesignerLauncher(); application.init(configResourcePath, additionalBeansResource, additionalConfigResource, showAlpha, showBeta); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { try { application.go(); application.registerCloseAction(); } catch (final Exception e) { final String msg = "Exception caught at top level of ComponentDesigner launch: " + e.toString(); log.error(msg, e); System.exit(0); } log.debug("Leaving runnable run section."); } }); }
From source file:Main.java
/** * Sets the font used for HTML displays to the specified font. Components * that display HTML do not necessarily honor font properties, since the * HTML document can override these values. Calling {@code setHtmlFont} * after the data is set will force the HTML display to use the font * specified to this method./*from ww w. jav a 2s . c o m*/ * * @param doc * the HTML document to update * @param font * the font to use * @throws NullPointerException * if any parameter is {@code null} */ public static void setHtmlFont(HTMLDocument doc, Font font) { String stylesheet = String.format(STYLESHEET, font.getName(), font.getSize(), font.getName(), font.getSize()); try { doc.getStyleSheet().loadRules(new StringReader(stylesheet), null); } catch (IOException e) { //this should never happen with our sheet throw new IllegalStateException(e); } }
From source file:Main.java
/** * Returns a string with all fonts used by Swing's UIManager. */// w w w . j a va 2 s. c o m public static String getUIFonts() { final StringBuffer fonts = new StringBuffer(128); fonts.append("Default font: "); fonts.append(getUIFont().toString()); final Enumeration<Object> keys = UIManager.getLookAndFeelDefaults().keys(); String lf = System.getProperty("line.separator"); while (keys.hasMoreElements()) { final Object key = keys.nextElement(); final Object value = UIManager.get(key); if (value instanceof Font) { final Font ifont = (Font) value; fonts.append(lf + key.toString() + " " + ifont.getName() + " " + ifont.getStyle() + " " + ifont.getSize()); } } return fonts.toString(); }
From source file:Main.java
public static Font createBoldFont(Font font) { if (font == null) { throw new NullPointerException("font == null"); }//from www . j a v a 2 s. co m String fontName = font.getName(); int fontSize = font.getSize(); return new Font(fontName, Font.BOLD, fontSize); }
From source file:Main.java
public static void addFontProperty(Document document, Element parent, String name, Font value) { addPropertyNode(document, parent, name).setAttribute(FONT_ATTR, value.getName() + "," + value.getStyle() + "," + value.getSize()); }
From source file:Main.java
public static String getNiceFontName(Font font) { if (font == null) return ""; StringBuilder buf = new StringBuilder(); buf.append(font.getName()); buf.append(", "); switch (font.getStyle()) { case Font.BOLD: buf.append("bold"); break;/* ww w . jav a 2 s.c o m*/ case Font.ITALIC: buf.append("italic"); break; case Font.PLAIN: buf.append("plain"); break; } buf.append(", "); buf.append(font.getSize()); return buf.toString(); }