Java Code Examples for java.awt.GraphicsEnvironment#getAvailableFontFamilyNames()
The following examples show how to use
java.awt.GraphicsEnvironment#getAvailableFontFamilyNames() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FrmPointSymbolSet.java From MeteoInfo with GNU Lesser General Public License v3.0 | 6 votes |
private void updateCharacterTab() { this.symbolControl1.setMarkerType(MarkerType.Character); this.symbolControl1.setSymbolNumber(256); this.jLabel_FontFamily.setEnabled(true); this.jComboBox_FontFamily.setEditable(true); this.jPanel_Outline.setEnabled(false); this.jSpinner_OutlineSize.setEnabled(false); this.jLabel_FillColor.setEnabled(true); this.jLabel_Color.setEnabled(true); this.jCheckBox_DrawFill.setEnabled(false); this.jComboBox_FontFamily.removeAllItems(); //FontUtil.registerWeatherFont(); GraphicsEnvironment gEnv = GraphicsEnvironment.getLocalGraphicsEnvironment(); String[] fonts = gEnv.getAvailableFontFamilyNames(); Font weatherFont = FontUtil.getWeatherFont(); if (weatherFont != null) this.jComboBox_FontFamily.addItem(weatherFont.getFontName()); for (String ff : fonts) { this.jComboBox_FontFamily.addItem(ff); } this.jComboBox_FontFamily.setSelectedItem(_pointBreak.getFontName()); }
Example 2
Source File: Initializer.java From stendhal with GNU General Public License v2.0 | 6 votes |
/** * Load a custom font. * * @param fontName Name of the font */ private static void initFont(String fontName) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); // Don't needlessly load the font if user already has it installed boolean needsLoading = true; for (String font : ge.getAvailableFontFamilyNames()) { if (fontName.equals(font)) { needsLoading = false; break; } } if (needsLoading) { String resource = "data/gui/" + fontName + ".ttf"; try { ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, DataLoader.getResourceAsStream(resource))); } catch (IOException|FontFormatException e) { logger.error("Error loading custom font '" + resource + '"', e); } } }
Example 3
Source File: PrintFontStyle.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public int print(Graphics g, PageFormat pf, int pageIndex) { if (pageIndex != 0) return NO_SUCH_PAGE; Graphics2D g2= (Graphics2D)g; g2.setPaint(Color.black); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); String[] fontList = ge.getAvailableFontFamilyNames(); g2.setFont (new Font ("Arial", Font.PLAIN, 20)); g2.drawString("Arial - Plain", 144, 120); g2.setFont (new Font ("Arial", Font.BOLD, 20)); g2.drawString("Arial - Bold", 144, 145); g2.setFont (new Font ("Arial", Font.ITALIC, 20)); g2.drawString("Arial - Italic", 144, 170); g2.setFont (new Font ("Times New Roman", Font.PLAIN, 20)); g2.drawString("Times New Roman - Plain", 144, 195); g2.setFont (new Font ("Times New Roman", Font.BOLD, 20)); g2.drawString("Times New Roman - Bold", 144, 220); g2.setFont (new Font ("Times New Roman", Font.ITALIC, 20)); g2.drawString("Times New Roman - Italic", 144, 245); return PAGE_EXISTS; }
Example 4
Source File: FontBuilder.java From ureport with Apache License 2.0 | 6 votes |
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { FontBuilder.applicationContext=applicationContext; GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment(); String[] fontNames=environment.getAvailableFontFamilyNames(); for(String name:fontNames){ systemFontNameList.add(name); } Collection<FontRegister> fontRegisters=applicationContext.getBeansOfType(FontRegister.class).values(); for(FontRegister fontReg:fontRegisters){ String fontName=fontReg.getFontName(); String fontPath=fontReg.getFontPath(); if(StringUtils.isEmpty(fontPath) || StringUtils.isEmpty(fontName)){ continue; } try { BaseFont baseFont=getIdentityFont(fontName,fontPath,applicationContext); if(baseFont==null){ throw new ReportComputeException("Font " + fontPath + " does not exist"); } fontMap.put(fontName, baseFont); } catch (Exception e) { e.printStackTrace(); throw new ReportComputeException(e); } } }
Example 5
Source File: JFontChooser.java From PolyGlot with MIT License | 5 votes |
protected String[] getFontFamilies() { if (fontFamilyNames == null) { GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); fontFamilyNames = env.getAvailableFontFamilyNames(); } return fontFamilyNames; }
Example 6
Source File: SVGFontProvider.java From swcv with MIT License | 5 votes |
private boolean isFontIstalled(String name) { if (installedFonts == null) { installedFonts = new HashSet<String>(); GraphicsEnvironment g = null; g = GraphicsEnvironment.getLocalGraphicsEnvironment(); for (String fontName : g.getAvailableFontFamilyNames()) installedFonts.add(fontName); } return installedFonts.contains(name); }
Example 7
Source File: AngelFontVisualPanel1.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** Creates new form AngelFontVisualPanel1 */ public AngelFontVisualPanel1() { initComponents(); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); String[] fontNames = ge.getAvailableFontFamilyNames(); jList1.setListData(fontNames); }
Example 8
Source File: SharedFunctions.java From zap-extensions with Apache License 2.0 | 5 votes |
public static boolean fontExists(String name) { GraphicsEnvironment g = null; g = GraphicsEnvironment.getLocalGraphicsEnvironment(); String[] fonts = g.getAvailableFontFamilyNames(); for (int i = 0; i < fonts.length; i++) { // System.out.println(fonts[i]); if (fonts[i].equals(name)) { setDefaultFont(name); setExistsFont(true); return true; } } return false; }
Example 9
Source File: FontComboBox.java From pumpernickel with MIT License | 5 votes |
/** * Create the Fonts this combobox should display, in the order they'll * be listed. Subclasses may override this to provide their own special * set of Fonts. */ protected SortedMap<String, Font> createFonts() { Comparator<String> comparator = new HumanStringComparator(); SortedMap<String, Font> returnValue = new TreeMap<>(comparator); // first, populate the fonts on this computer: GraphicsEnvironment ge = GraphicsEnvironment .getLocalGraphicsEnvironment(); String[] s = ge.getAvailableFontFamilyNames(); for (String fontName : s) { returnValue.put(fontName, new Font(fontName, 0, 16)); } return returnValue; }
Example 10
Source File: JFontChooser.java From brModelo with GNU General Public License v3.0 | 5 votes |
protected String[] getFontFamilies() { if (fontFamilyNames == null) { GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); fontFamilyNames = env.getAvailableFontFamilyNames(); } return fontFamilyNames; }
Example 11
Source File: JFontChooser.java From Luyten with Apache License 2.0 | 5 votes |
protected String[] getFontFamilies() { if (fontFamilyNames == null) { GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); fontFamilyNames = env.getAvailableFontFamilyNames(); } return fontFamilyNames; }
Example 12
Source File: AlloyGraphics.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * The fontNames can contain a comma separated list of font names. This function * will parse that list trying to match the first font name that can be found in * the list against the list of available font families. Spaces around font * names are stripped. For example: * * <pre> * 'Input Mono, Lucinda Sans Mono, Courier New, Courier, monofont' * </pre> * <p> * A special case is when a font name starts with a $, in that case the name is * looked up in the System properties. . * <p> * If none of the names can be found, the last font is returned as a desperate * last attempt. * * @param fontNames comma separated list of font names **/ public static synchronized String matchBestFontName(String fontNames) { String[] names = fontNames.trim().split("\\s*,\\s*"); if (availableFontNames.isEmpty()) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); String[] availableFontFamilyNames = ge.getAvailableFontFamilyNames(); for (String availableName : availableFontFamilyNames) { availableFontNames.put(toSoundex(availableName), availableName); } } for (String name : names) { if (name.startsWith("$")) { name = name.substring(1); Font font = Font.getFont(name); if (font != null) return font.getFontName(); } else { String soundex = toSoundex(name); String fontName = availableFontNames.get(soundex); if (fontName != null) return name; } } return names[names.length - 1]; }
Example 13
Source File: FontChooser.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
/** * Creates new form FontChooser */ public FontChooser(java.awt.Dialog parent, boolean modal, Font curFont) { super(parent, "Font Chooser", modal); initComponents(); GraphicsEnvironment gEnv = GraphicsEnvironment.getLocalGraphicsEnvironment(); String[] fonts = gEnv.getAvailableFontFamilyNames(); this.jList_Font.removeAll(); DefaultListModel listModel = new DefaultListModel(); for (String ff : fonts) { listModel.addElement(ff); } this.jList_Font.setModel(listModel); this.jList_Font.setSelectedValue(curFont.getFontName(), true); }
Example 14
Source File: JFontChooser.java From PacketProxy with Apache License 2.0 | 5 votes |
protected String[] getFontFamilies() { if (fontFamilyNames == null) { GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); fontFamilyNames = env.getAvailableFontFamilyNames(); } return fontFamilyNames; }
Example 15
Source File: LabelFontsOptionsPanelController.java From constellation with Apache License 2.0 | 5 votes |
@Override public void update() { final Preferences prefs = NbPreferences.forModule(LabelFontsPreferenceKeys.class); final LabelFontsOptionsPanel labelFontsOptionsPanel = getPanel(); labelFontsOptionsPanel.setUseMultiFonts(prefs.getBoolean(LabelFontsPreferenceKeys.USE_MULTI_FONTS, LabelFontsPreferenceKeys.USE_MULTI_FONTS_DEFAULT)); labelFontsOptionsPanel.setFontList(prefs.get(LabelFontsPreferenceKeys.FONT_LIST, LabelFontsPreferenceKeys.FONT_LIST_DEFAULT)); // do this last to ensure panel updates correctly labelFontsOptionsPanel.setUseDefaultSettings(prefs.getBoolean(LabelFontsPreferenceKeys.USE_DEFAULTS, LabelFontsPreferenceKeys.USE_DEFAULTS_DEFAULT)); // Put the font loading here (rather than the constructor) so the user can install a new font and see it without restarting. final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); String[] availableFonts = ge.getAvailableFontFamilyNames(Locale.getDefault()); final String os = System.getProperty("os.name"); if (os.toLowerCase().contains("win")) { availableFonts = otfFontFilesWindows(availableFonts); } // TODO: look for unix fonts. Arrays.sort(availableFonts); labelFontsOptionsPanel.setAvailableFonts(availableFonts); // TODO: read settings and initialize GUI // Example: // someCheckBox.setSelected(Preferences.userNodeForPackage(LabelFontsPanel.class).getBoolean("someFlag", false)); // or for org.openide.util with API spec. version >= 7.4: // someCheckBox.setSelected(NbPreferences.forModule(LabelFontsPanel.class).getBoolean("someFlag", false)); // or: // someTextField.setText(SomeSystemOption.getDefault().getSomeStringProperty()); }
Example 16
Source File: Utilidades.java From brModelo with GNU General Public License v3.0 | 4 votes |
public static String[] getFontsList() { GraphicsEnvironment gEnv = GraphicsEnvironment .getLocalGraphicsEnvironment(); String envfonts[] = gEnv.getAvailableFontFamilyNames(); return envfonts; }
Example 17
Source File: ListJavaFonts.java From SWET with MIT License | 4 votes |
public static void main(String[] args) { List<String> monospaceFontFamilyNames = new ArrayList<>(); GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment .getLocalGraphicsEnvironment(); String[] fontFamilyNames = graphicsEnvironment .getAvailableFontFamilyNames(); BufferedImage bufferedImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); Graphics graphics = bufferedImage.createGraphics(); for (String fontFamilyName : fontFamilyNames) { boolean isMonospaced = true; // int fontStyle = Font.PLAIN; int fontSize = 12; Font font = new Font(fontFamilyName, fontStyle, fontSize); @SuppressWarnings("serial") List<Integer> codePoints = new ArrayList<Integer>() { { add(108); /* l */ add(109); /* m */ add(119); /* w */ add(49); /* 1 */ add(52); /* 4 */ } }; FontMetrics fontMetrics = graphics.getFontMetrics(font); int firstCharacterWidth = 0; boolean hasFirstCharacterWidth = false; for (int codePoint : codePoints) { if (Character.isValidCodePoint(codePoint) && (Character.isLetter(codePoint) || Character.isDigit(codePoint))) { char character = (char) codePoint; int characterWidth = fontMetrics.charWidth(character); if (hasFirstCharacterWidth) { if (characterWidth != firstCharacterWidth) { isMonospaced = false; break; } } else { firstCharacterWidth = characterWidth; hasFirstCharacterWidth = true; } } } if (isMonospaced) { monospaceFontFamilyNames.add(fontFamilyName); } } graphics.dispose(); for (String fontFamily : monospaceFontFamilyNames) { System.out.println(fontFamily); } }
Example 18
Source File: FontChooserPanel.java From ccu-historian with GNU General Public License v3.0 | 4 votes |
/** * Standard constructor - builds a FontChooserPanel initialised with the * specified font. * * @param font the initial font to display. */ public FontChooserPanel(final Font font) { final GraphicsEnvironment g = GraphicsEnvironment.getLocalGraphicsEnvironment(); final String[] fonts = g.getAvailableFontFamilyNames(); setLayout(new BorderLayout()); final JPanel right = new JPanel(new BorderLayout()); final JPanel fontPanel = new JPanel(new BorderLayout()); fontPanel.setBorder(BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), localizationResources.getString("Font"))); this.fontlist = new JList(fonts); final JScrollPane fontpane = new JScrollPane(this.fontlist); fontpane.setBorder(BorderFactory.createEtchedBorder()); fontPanel.add(fontpane); add(fontPanel); final JPanel sizePanel = new JPanel(new BorderLayout()); sizePanel.setBorder(BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), localizationResources.getString("Size"))); this.sizelist = new JList(SIZES); final JScrollPane sizepane = new JScrollPane(this.sizelist); sizepane.setBorder(BorderFactory.createEtchedBorder()); sizePanel.add(sizepane); final JPanel attributes = new JPanel(new GridLayout(1, 2)); this.bold = new JCheckBox(localizationResources.getString("Bold")); this.italic = new JCheckBox(localizationResources.getString("Italic")); attributes.add(this.bold); attributes.add(this.italic); attributes.setBorder(BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), localizationResources.getString("Attributes"))); right.add(sizePanel, BorderLayout.CENTER); right.add(attributes, BorderLayout.SOUTH); add(right, BorderLayout.EAST); setSelectedFont(font); }
Example 19
Source File: FontChooserPanel.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Standard constructor - builds a FontChooserPanel initialised with the * specified font. * * @param font the initial font to display. */ public FontChooserPanel(Font font) { GraphicsEnvironment g = GraphicsEnvironment.getLocalGraphicsEnvironment(); String[] fonts = g.getAvailableFontFamilyNames(); setLayout(new BorderLayout()); JPanel right = new JPanel(new BorderLayout()); JPanel fontPanel = new JPanel(new BorderLayout()); fontPanel.setBorder(BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), localizationResources.getString("Font"))); this.fontlist = new JList(fonts); JScrollPane fontpane = new JScrollPane(this.fontlist); fontpane.setBorder(BorderFactory.createEtchedBorder()); fontPanel.add(fontpane); add(fontPanel); JPanel sizePanel = new JPanel(new BorderLayout()); sizePanel.setBorder(BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), localizationResources.getString("Size"))); this.sizelist = new JList(SIZES); JScrollPane sizepane = new JScrollPane(this.sizelist); sizepane.setBorder(BorderFactory.createEtchedBorder()); sizePanel.add(sizepane); JPanel attributes = new JPanel(new GridLayout(1, 2)); this.bold = new JCheckBox(localizationResources.getString("Bold")); this.italic = new JCheckBox(localizationResources.getString("Italic")); attributes.add(this.bold); attributes.add(this.italic); attributes.setBorder(BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), localizationResources.getString("Attributes"))); right.add(sizePanel, BorderLayout.CENTER); right.add(attributes, BorderLayout.SOUTH); add(right, BorderLayout.EAST); setSelectedFont(font); }
Example 20
Source File: FontChooserPanel.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Standard constructor - builds a FontChooserPanel initialised with the * specified font. * * @param font the initial font to display. */ public FontChooserPanel(Font font) { GraphicsEnvironment g = GraphicsEnvironment.getLocalGraphicsEnvironment(); String[] fonts = g.getAvailableFontFamilyNames(); setLayout(new BorderLayout()); JPanel right = new JPanel(new BorderLayout()); JPanel fontPanel = new JPanel(new BorderLayout()); fontPanel.setBorder(BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), localizationResources.getString("Font"))); this.fontlist = new JList(fonts); JScrollPane fontpane = new JScrollPane(this.fontlist); fontpane.setBorder(BorderFactory.createEtchedBorder()); fontPanel.add(fontpane); add(fontPanel); JPanel sizePanel = new JPanel(new BorderLayout()); sizePanel.setBorder(BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), localizationResources.getString("Size"))); this.sizelist = new JList(SIZES); JScrollPane sizepane = new JScrollPane(this.sizelist); sizepane.setBorder(BorderFactory.createEtchedBorder()); sizePanel.add(sizepane); JPanel attributes = new JPanel(new GridLayout(1, 2)); this.bold = new JCheckBox(localizationResources.getString("Bold")); this.italic = new JCheckBox(localizationResources.getString("Italic")); attributes.add(this.bold); attributes.add(this.italic); attributes.setBorder(BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), localizationResources.getString("Attributes"))); right.add(sizePanel, BorderLayout.CENTER); right.add(attributes, BorderLayout.SOUTH); add(right, BorderLayout.EAST); setSelectedFont(font); }