• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Repaint() not working?

 
Chris Copeland
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 9266
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic