Files
swing-examples/Writerside2/topics/Font.md
2024-06-12 13:10:10 +09:00

714 B

Font

Font font = Font.createFont(Font.TRUETYPE_FONT, new File("Abc.ttf"));
return font.deriveFont(12.f);
  • getFamily()

  • getFontName()

  • getAttributes()

  • graphics2D.getFont() / graphics2D.setFont(Font)

  • Font.createFont(int,InputStream)

  • deriveFont()

  • graphicsEnvironment.getAvailableFontFamilyNames()

  • graphicsEnvironment.getAllFonts()

HashMap<TextAttribute,Object> map = new HashMap<>();
map.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
font = font.deriveFont(map);

FontMetrics

FontMetrics fontMetrics = graphics2D.getFontMetrics(font);
int textHeight = fontMetrics.getHeight();
int textWidth = fontMetrics.stringWidth("Hello");