   [java] JWindow and drawString
  Hi, I've been programming java for quite a while now, and I want to start making little games. I decided to start learning how to work with the java2D library, but ran into a problem today.I create a JWindow, and set it to fullscreen. Then I make a class extending the JPanel class, on which I put some text using Graphics2D.drawString(string).I add an instance of that class to my JWindow, but no text seams to appear.When I minimize the JWindow, and then maximize it again my text shows up.Why is this, and how could I fix this?   
  You can override the paint(Graphics g) method of the JPanel. This paint() method is called when the window need to be repainted(in the truth, the repaint() method is called and it calls paint()). Then, in your class(the one derived from JPanel) create a paint method and put all the drawing code inside of it, you must draw through the Graphics g which comes as parameter. Something like this:public class SomePanel extends JPanel{    public void paint(Graphics g)    {   //call base class paint() method so that it'll draw some basic stuff. It may be useless in some cases   super.paint(g);   g.setColor(Color.black);   g.serFont(new Font("Courier New", Font.PLAIN, 20);   g.drawString("HEy!!", 5, 30);    }}hth   ;  hm, what I had was this:public void paintComponent(Graphics comp) {String text = "Ay Caramba!";super.paintComponent(comp);Graphics2D comp2D = (Graphics2D)comp;comp2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);Font font = new Font("Sans serif", Font.BOLD, 18);FontMetrics metrics = getFontMetrics(font);comp2D.setFont(font);int x = (getSize().width - metrics.stringWidth(text)) / 2;int y = getSize().height / 2;System.out.println("drawing...");comp2D.drawString(text, x, y);System.out.println("ready");}Derived it from some example code from a book on java.The paintComponent method is supposed to be called for every draw or redraw, but it appears that it is not called the first time.Gonna check out the paint method :)EDIT: the two println's are for debugging, let me translate it to make it clearAnother edit: The paint() method seems to give the same problem, when I minimize the screen though, I see on my console output that the text has allready been rendered 3 times. Maybe it has something with the pc I'm using, it's pretty slow, gonna test it on a better system. Shouldn't give a problem normally for such simple things, I can still run photoshop cs3 (slow, but it runs).   ;  I've found the problem now, just had to change the order of some things.Working code is:public void paintComponent(Graphics comp) {String text = "Drawing a String";super.paintComponent(comp);Graphics2D comp2D = (Graphics2D)comp;comp2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);Font font = new Font("Sans serif", Font.BOLD, 18);FontMetrics metrics = getFontMetrics(font);comp2D.setFont(font);int x = (getSize().width - metrics.stringWidth(text)) / 2;int y = getSize().height / 2;comp2D.drawString(text, x, y);}