This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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: 8876
    
    8

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]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Repaint() not working?