本文整理汇总了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;
}
示例2: getFontFamilies
import java.awt.GraphicsEnvironment; //导入方法依赖的package包/类
private String[] getFontFamilies() {
if (fontFamilyNames == null) {
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
fontFamilyNames = env.getAvailableFontFamilyNames();
}
return fontFamilyNames;
}
示例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);
}
}
示例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);
}
示例5: getFontFamilies
import java.awt.GraphicsEnvironment; //导入方法依赖的package包/类
protected String[] getFontFamilies() {
if (fontFamilyNames == null) {
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
fontFamilyNames = env.getAvailableFontFamilyNames();
}
return fontFamilyNames;
}
示例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);
}
示例7: getFontFamilies
import java.awt.GraphicsEnvironment; //导入方法依赖的package包/类
protected String[] getFontFamilies()
{
if (fontFamilyNames == null)
{
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
fontFamilyNames = env.getAvailableFontFamilyNames();
}
return fontFamilyNames;
}
示例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);
}
}
示例9: getFontsList
import java.awt.GraphicsEnvironment; //导入方法依赖的package包/类
public static String[] getFontsList() {
GraphicsEnvironment gEnv = GraphicsEnvironment
.getLocalGraphicsEnvironment();
String envfonts[] = gEnv.getAvailableFontFamilyNames();
return envfonts;
}