/**
* Combobox that displays a list of all available fonts, showing the name of the
* font in the font itself.
- *
+ *
* @see GraphicsEnvironment#getAllFonts()
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
- * @version $Id$
*/
public class FontComboBox extends JComboBox {
- /**
- * Creates a new font combo box.
- */
- public FontComboBox() {
- super();
+ /** The font names. */
+ private static final String[] fontNames;
+
+ static {
Font[] allFonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
- String[] fontNames = new String[allFonts.length];
+ System.out.println("got " + allFonts.length + " fonts");
+ fontNames = new String[allFonts.length];
int fontIndex = 0;
for (Font font: allFonts) {
fontNames[fontIndex++] = font.getName();
}
+ }
+
+ /**
+ * Creates a new font combo box.
+ */
+ public FontComboBox() {
+ super();
setModel(new DefaultComboBoxModel(fontNames));
setRenderer(new FontCellRenderer());
}
/**
* The cell renderer for the font name cells.
- *
+ *
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
- * @version $Id$
*/
private static class FontCellRenderer extends JLabel implements ListCellRenderer {