The delay is due to the fact that getAvailableFontFamilyNames creates a 1 pt font for every font it can find. It allows the JVM to distinguish between fonts it can use and things that only look like they may be fonts.
The best approach is to call it in a SwingWorker and then update the combo from the done method.
update:
The poster's code updated to use the generified SwingWorker.
Note: I am returning the array of names as it eliminates the need for synchronization.
SwingWorker aWorker<String[],Void> = new SwingWorker<String[],Void>() {
protected void done() {
String[] fontNames = get();
for (int i = 0; i < fontNames.length; i++)
fontFamily.addItem(fontNames[i]);
}
@Override
protected String[] doInBackground() throws Exception {
GraphicsEnvironment env = GraphicsEnvironment .getLocalGraphicsEnvironment();
return env.getAvailableFontFamilyNames();
}
};
aWorker.run();