2010年11月13日 星期六

Java - 字型處理

取得所有Font
Font[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
for(Font f: fonts){
System.out.println(f.getName());
}
自行設定字型
Font font = new Font(fontName, fontStyle, fontSize);
Font newFont = font.deriveFont(fontType); // int
Font newFont = font.deriveFont(fontSize); // float
Font newFont = font.deriveFont(fontType, fontSize); // int, float
設定Font(在JPanel中)
setFont(font);
取得FontMetrics,並用其取得文字在某種字型時的資訊
FontMetrics metrics = getFontMetrics(font);
messageWidth = metrics.stringWidth(message);

沒有留言:

張貼留言