getFontMetrics() taking 8000ms on first call in Java Applet

724 Views Asked by At

Making a call to getFontMetrics()in my java applet is taking between 5000ms and 22000ms to return! Subsequent calls seem to take a negligible amount of time (0-16ms)

I have to admit I'm running on a machine with bare bones graphics drivers (Graphics card is broken so I can't use the Nvidia Drivers), However, this seems to be an astronomical performance hit on an otherwise simple applet!

Does anyone have any ideas what might be causing this? I've come across other examples on stackoveflow with the same problem but seemingly no satisfactory answers. I'm running this in eclipse, but running in IE, Mozilla and Chrome produce same delays.

The SSCCE as Requested:

import java.applet.Applet;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;

public class fontProblems extends Applet{
    Graphics2D g;
    FontMetrics fm;
    Font font=new Font("Roman", Font.BOLD, 36);
    public void paint(Graphics g2){
        g = (Graphics2D) g2;
        fm = g.getFontMetrics(font);
    }
}
1

There are 1 best solutions below

0
On

According to documentation (http://docs.oracle.com/javase/7/docs/api/java/awt/Font.html), AWT components can only use logical fonts. Changing font to "SansSerif" solved the issue for me.