Drawing to a JFrame (Java) - must drag the window around to see the drawing?

slugg

Diamond Member
Feb 17, 2002
4,723
80
91
So I'm just trying to hack together a little proof of concept app. It involves drawing directly to a JFrame. Everything works just fine, except in order to actually see the shapes I've drawn, I need to drag the window off the screen, then bring it back. Since 99.9% of all the programming I've ever done in any language has not involved a GUI, I'm a bit perplexed. Also, I haven't touched Java in 4 years, so I forgot all the intricacies of it. I'm missing something stupid...

Obviously this has something to do with refreshing/redrawing/whatever the window. I'm not quite sure how to properly attack this problem. Unfortunately, I'm not allowed to show you my source code. I can say this: I'm using the NetBeans IDE. I just made a JFrame and added a menu bar to it. When one of the menu items is clicked, my code draws something directly to the frame (under the menu bar). That's about it - nothing special. I do my drawing in the overrode paint(Graphics g) method.

Any ideas?
 

tatteredpotato

Diamond Member
Jul 23, 2006
3,934
0
76
In what method should I try that?

Whenever you do something that would require the contents of the jframe to be redrawn. Update essentially will cause the jframe to be redrawn (this is what happens when you move it off screen).