serif | This text is in a serif font. Often used for blocks of text (eg, Times). |
sansserif | This text is in a SansSerif font. Often used for titles (eg, Arial or Helvetica). |
monospaced | This text is in a Monospaced font, often used for computer text (eg, Courier). |
You can also get a list of the system fonts on the host computer. See below.
Font f = new Font(name, style, size);
String name | int style | int size |
"serif" "sansserif" "monospaced" or a system font. |
Font.PLAIN Font.BOLD Font.ITALIC Font.BOLD+Font.ITALIC |
Integer point size -- typically in range 10-48. |
JButton b = new JButton("OK"); b.setFont(new Font("sansserif", Font.BOLD, 32));
// Font info is obtained from the current graphics environment. GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); //--- Get an array of font names (smaller than the number of fonts) String[] fontNames = ge.getAvailableFontFamilyNames(); //--- Get an array of fonts. It's preferable to use the names above. Font[] allFonts = ge.getAllFonts();