Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes Repaint() not working? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Repaint() not working?" Watch "Repaint() not working?" New topic
Author

Repaint() not working?

Chris Copeland
Greenhorn

Joined: Oct 20, 2003
Posts: 10
Hello all,
I am writing my first swing application. One of the requirements is to put a scrolling message along the bottom of the application. I have my main class extending JFrame and implementing Runnable. Inside run, I am doing the following:
while (true) {
frame.x = frame.x - 1;
if (frame.x == (frame.x * -1))
{
frame.x = frameSize.width;
}
frame.getContentPane().repaint();
try {
Thread.sleep(10);
} catch (Exception e) { }
}
Inside my class I have also overriden paint() with:
g.drawString(scrollingMsg, x, y);
The problem is that when I run, the thread IS starting, but the repaint() command I use in run never repaints the screen. I can see that the thread is working because if I move another window in front of the Frame, then I can just see that the message has been printed (which then dissappears ms's later).
Anyone have a suggestion? am I just doing this completely wrong?
Thanks,
Chris
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

Originally posted by Chris Copeland:
Hello all,
I am writing my first swing application. One of the requirements is to put a scrolling message along the bottom of the application. I have my main class extending JFrame and implementing Runnable. Inside run, I am doing the following:
while (true) {
frame.x = frame.x - 1;
if (frame.x == (frame.x * -1))
{
frame.x = frameSize.width;
}
frame.getContentPane().repaint();
try {
Thread.sleep(10);
} catch (Exception e) { }
}
Inside my class I have also overriden paint() with:
g.drawString(scrollingMsg, x, y);
The problem is that when I run, the thread IS starting, but the repaint() command I use in run never repaints the screen. I can see that the thread is working because if I move another window in front of the Frame, then I can just see that the message has been printed (which then dissappears ms's later).
Anyone have a suggestion? am I just doing this completely wrong?
Thanks,
Chris

You are calling repaint() on the content pane, but painting the graphics content of the JFrame. Not the same thing. If you call frame.repaint() it should work.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Repaint() not working?
 
Similar Threads
Web interface to delete folder
NEED HELP! JRE 1.5 Paint Issue
MQQueueConnectionFactory and threading
Reflection and magic value
Animation Applet