aspose file tools*
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
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: 8927
    
    9

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]
 
Consider Paul's rocket mass heater.
 
subject: Repaint() not working?