【获取字体名称代码】
import java.awt.*;
/**
* Created by zdy on 2017/3/16.
*/
public class GetLocalFontFamily {
public static void main(String[] agrs) {
//获取系统中可用的字体的名字
GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
String[] fontName = e.getAvailableFontFamilyNames();
for (int i = 0; i < fontName.length; i++) {
System.out.println(fontName[i]);
}
}
}
【测试结果,MacBookPro 16款默认的,印象中没装过字体】
Al Bayan
Al Nile
Al Tarikh
American Typewriter
Andale Mono
Apple Braille
Apple Chancery
Apple Color Emoji
Apple LiGothic
Apple LiSung
Apple SD Gothic Neo
Apple Symbols
AppleGothic
AppleMyungjo
Arial
Arial Black
Arial Hebrew
Arial Hebrew Scholar
Arial Narrow
Arial Rounded MT Bold
Arial Unicode MS
Athelas
Avenir
Avenir Next
Avenir Next Condensed
Ayuthaya
Baghdad
Bangla MN
Bangla Sangam MN
Baoli SC
Baoli TC
Baskerville
Beirut
BiauKai
Big Caslon
Bodoni 72
Bodoni 72 Oldstyle
Bodoni 72 Smallcaps
Bodoni Ornaments
Bradley Hand
Brush Script MT
Chalkboard
Chalkboard SE
Chalkduster
Charter
Cochin
Comic Sans MS
Copperplate
Corsiva Hebrew
Courier
Courier New
Damascus
DecoType Naskh
Devanagari MT
Devanagari Sangam MN
Dialog
DialogInput
Didot
DIN Alternate
DIN Condensed
Diwan Kufi
Diwan Thuluth
Euphemia UCAS
Farah
Farisi
Futura
GB18030 Bitmap
Geeza Pro
Geneva
Georgia
Gill Sans
Gujarati MT
Gujarati Sangam MN
GungSeo
Gurmukhi MN
Gurmukhi MT
Gurmukhi Sangam MN
Hannotate SC
Hannotate TC
HanziPen SC
HanziPen TC
HeadLineA
Hei
Heiti SC
Heiti TC
Helvetica
Helvetica Neue
Herculanum
Hiragino Kaku Gothic Pro
Hiragino Kaku Gothic ProN
Hiragino Kaku Gothic Std
Hiragino Kaku Gothic StdN
Hiragino Maru Gothic Pro
Hiragino Maru Gothic ProN
Hiragino Mincho Pro
Hiragino Mincho ProN
Hiragino Sans
Hiragino Sans CNS
Hiragino Sans GB
Hoefler Text
Impact
InaiMathi
Iowan Old Style
ITF Devanagari
ITF Devanagari Marathi
Kai
Kailasa
Kaiti SC
Kaiti TC
Kannada MN
Kannada Sangam MN
Kefa
Khmer MN
Khmer Sangam MN
Klee
Kohinoor Bangla
Kohinoor Devanagari
Kohinoor Telugu
Kokonor
Krungthep
KufiStandardGK
Lantinghei SC
Lantinghei TC
Lao MN
Lao Sangam MN
Libian SC
Libian TC
LiHei Pro
LingWai SC
LingWai TC
LiSong Pro
Lucida Bright
Lucida Grande
Lucida Sans
Lucida Sans Typewriter
Luminari
Malayalam MN
Malayalam Sangam MN
Marion
Marker Felt
Menlo
Microsoft Sans Serif
Mishafi
Mishafi Gold
Monaco
Monospaced
Mshtakan
Muna
Myanmar MN
Myanmar Sangam MN
Nadeem
Nanum Brush Script
Nanum Gothic
Nanum Myeongjo
Nanum Pen Script
New Peninim MT
Noteworthy
Optima
Oriya MN
Oriya Sangam MN
Osaka
Palatino
Papyrus
PCMyungjo
Phosphate
PilGi
PingFang HK
PingFang SC
PingFang TC
Plantagenet Cherokee
PT Mono
PT Sans
PT Sans Caption
PT Sans Narrow
PT Serif
PT Serif Caption
Raanana
Sana
SansSerif
Sathu
Savoye LET
Seravek
Serif
Shree Devanagari 714
SignPainter
Silom
Sinhala MN
Sinhala Sangam MN
Skia
Snell Roundhand
Songti SC
Songti TC
STFangsong
STHeiti
STIXGeneral
STIXIntegralsD
STIXIntegralsSm
STIXIntegralsUp
STIXIntegralsUpD
STIXIntegralsUpSm
STIXNonUnicode
STIXSizeFiveSym
STIXSizeFourSym
STIXSizeOneSym
STIXSizeThreeSym
STIXSizeTwoSym
STIXVariants
STKaiti
STSong
Sukhumvit Set
Superclarendon
Symbol
Tahoma
Tamil MN
Tamil Sangam MN
TeamViewer12
Telugu MN
Telugu Sangam MN
Thonburi
Times
Times New Roman
Toppan Bunkyu Gothic
Toppan Bunkyu Midashi Gothic
Toppan Bunkyu Midashi Mincho
Toppan Bunkyu Mincho
Trattatello
Trebuchet MS
Tsukushi A Round Gothic
Tsukushi B Round Gothic
Verdana
Waseem
Wawati SC
Wawati TC
Webdings
Weibei SC
Weibei TC
Wingdings
Wingdings 2
Wingdings 3
Xingkai SC
Xingkai TC
Yuanti SC
Yuanti TC
YuGothic
YuKyokasho
YuKyokasho Yoko
YuMincho
YuMincho +36p Kana
Yuppy SC
Yuppy TC
Zapf Dingbats
Zapfino
【示例】
public static final Font DEFAULT_FONT_FUNCTION=new Font(Font.SANS_SERIF,Font.BOLD,24);//SansSerif 在Font.java中有定义
public static final Font DEFAULT_FONT=new Font("STHeiti",Font.BOLD,24);//黑体
public static final Font DEFAULT_FONT_SPACE=new Font("Xingkai TC",Font.BOLD,24);//行楷