當前位置: 首頁>>代碼示例>>Java>>正文


Java GraphicsEnvironment.getAvailableFontFamilyNames方法代碼示例

本文整理匯總了Java中java.awt.GraphicsEnvironment.getAvailableFontFamilyNames方法的典型用法代碼示例。如果您正苦於以下問題:Java GraphicsEnvironment.getAvailableFontFamilyNames方法的具體用法?Java GraphicsEnvironment.getAvailableFontFamilyNames怎麽用?Java GraphicsEnvironment.getAvailableFontFamilyNames使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.GraphicsEnvironment的用法示例。


在下文中一共展示了GraphicsEnvironment.getAvailableFontFamilyNames方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: print

import java.awt.GraphicsEnvironment; //導入方法依賴的package包/類
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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:PrintFontStyle.java

示例2: getFontFamilies

import java.awt.GraphicsEnvironment; //導入方法依賴的package包/類
private String[] getFontFamilies() {
    if (fontFamilyNames == null) {
        GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
        fontFamilyNames = env.getAvailableFontFamilyNames();
    }
    return fontFamilyNames;
}
 
開發者ID:takun2s,項目名稱:smile_1.5.0_java7,代碼行數:8,代碼來源:FontChooser.java

示例3: loadFonts

import java.awt.GraphicsEnvironment; //導入方法依賴的package包/類
/**
 * Loads all available fonts into the combo
 *
 */
private void loadFonts() {
	GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
	String[] fontNames = ge.getAvailableFontFamilyNames();
	
	for(String font : fontNames) {
		fontComboModel.addElement(font);
	}
}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:13,代碼來源:FengFonts.java

示例4: run

import java.awt.GraphicsEnvironment; //導入方法依賴的package包/類
public void run()
{
  GraphicsEnvironment ge = null;
  // -= Simon Lessard =-
  // TODO: Check if synchronization is required
  Hashtable<String, Boolean> fontNames = null;

  try
  {
    ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

    if (ge != null)
    {
      String[] families = ge.getAvailableFontFamilyNames();

      if ((families != null) && (families.length > 0))
      {
        fontNames = new Hashtable<String, Boolean>(families.length);
        for (int i = 0; i < families.length; i++)
        {
          String name = families[i].toLowerCase();
          fontNames.put(name, Boolean.TRUE);
        }
      }
    }
  }
  catch (Throwable t)
  {
    // If any exception occurs during getLocalGraphicsEnvironment(),
    // we assume we've got a non-graphical environment
    _LOG.warning(_EXCEPTION_MESSAGE, t);
  }

  __setFontsLoaded(fontNames);
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:36,代碼來源:GraphicsUtils.java

示例5: getFontFamilies

import java.awt.GraphicsEnvironment; //導入方法依賴的package包/類
protected String[] getFontFamilies() {
	if (fontFamilyNames == null) {
		GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
		fontFamilyNames = env.getAvailableFontFamilyNames();
	}
	return fontFamilyNames;
}
 
開發者ID:KevinPriv,項目名稱:Luyten4Forge,代碼行數:8,代碼來源:JFontChooser.java

示例6: getFont

import java.awt.GraphicsEnvironment; //導入方法依賴的package包/類
private static Font getFont() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    String[] fontNames = ge.getAvailableFontFamilyNames();
    String fontName = fontNames[0];
    for (String name : fontNames) {
        if ("Arial".equals(name)) {
            fontName = name;
            break;
        }
    }
    return new Font(fontName, Font.PLAIN, 30);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:bug8132119.java

示例7: getFontFamilies

import java.awt.GraphicsEnvironment; //導入方法依賴的package包/類
protected String[] getFontFamilies()
{
    if (fontFamilyNames == null)
    {
        GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
        fontFamilyNames = env.getAvailableFontFamilyNames();
    }
    return fontFamilyNames;
}
 
開發者ID:chcandido,項目名稱:brModelo,代碼行數:10,代碼來源:JFontChooser.java

示例8: main

import java.awt.GraphicsEnvironment; //導入方法依賴的package包/類
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);
		}
	}
 
開發者ID:sergueik,項目名稱:SWET,代碼行數:61,代碼來源:ListJavaFonts.java

示例9: getFontsList

import java.awt.GraphicsEnvironment; //導入方法依賴的package包/類
public static String[] getFontsList() {
    GraphicsEnvironment gEnv = GraphicsEnvironment
            .getLocalGraphicsEnvironment();
    String envfonts[] = gEnv.getAvailableFontFamilyNames();
    return envfonts;
}
 
開發者ID:chcandido,項目名稱:brModelo,代碼行數:7,代碼來源:Utilidades.java


注:本文中的java.awt.GraphicsEnvironment.getAvailableFontFamilyNames方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。