简体   繁体   中英

why does setFont take so much time?

I am trying to draw text on my screen this way:

    System.out.println(System.currentTimeMillis() + " 2.2 ");      //debug
    g.setFont(thisfont);
    System.out.println(System.currentTimeMillis() + " 2.2.1 ");    //debug
    g.drawString("hallo", x, y);
    System.out.println(System.currentTimeMillis() + " 2.2.2 ");    //debug
    g.drawString("hallo2", x, y2);
    System.out.println(System.currentTimeMillis() + " 2.2.3 ");    //debug

according to my debug panel the time that's between setting the font and the first drawString getting drawn is the problem (9 secs). here is the text on the debug panel:

1406377881939 2.2 
1406377881939 2.2.1 
1406377890799 2.2.2  
1406377890800 2.2.3 

why does this take so long, am I doing something wrong or is it just that setfont is not working good in combination with drawString?

it's a bit uneconomic to create a new Font each time paint() is called (which happens a lot), you could move that to your constructor. and the font should be changed to some orthodox fonts (Arial,Calibri etc)

try g.setFont(new Font("Arial", Font.PLAIN, 8))

read more...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM