There is a panel that on the form in the paintComponent method I draw a string. But when launched from Netbeans, and just a jar file for about one and a half seconds, a window like a redraw appears.
public class MyPanel extends JPanel { public void paintComponent( Graphics g ) { super.paintComponent( g ); Font textFont = new Font( "SanSerif", Font.BOLD, 20 ); String text = "This is text for testing"; g.setFont( textFont ); g.drawString( text, 10, 100 ); Graphics2D g2 = ( Graphics2D) g; } }
but if you remove g.setFont (textFont); then everything will work very quickly and leave it like this:
public class MyPanel extends JPanel { public void paintComponent( Graphics g ) { super.paintComponent( g ); Font textFont = new Font( "SanSerif", Font.BOLD, 20 ); String text = "This is text for testing"; g.drawString( text, 10, 100 ); Graphics2D g2 = ( Graphics2D) g; } }
if I'm after Graphics2D g2 = ( Graphics2D) g;
add
FontRenderContext context = g2.getFontRenderContext(); Rectangle2D textBounds = textFont.getStringBounds( text, context );
it will run a little longer, again with a non-redrawn window.