Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Swing Application Flickering?

 
Braden Steffaniak
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im making a swing application that is updated frequently. Because of this, it is flickering a whole lot. How can I fix this? It is not a web applet.
 
Paul Clapham
Sheriff
Pie
Posts: 20962
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hard to tell from the little information provided. I can take a shot in the dark and recommend the Concurrency in Swing tutorial, though.
 
Stephan van Hulst
Bartender
Pie
Posts: 5589
54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Braden, welcome to CodeRanch.

If you post an SSCCE that demonstrates your problem, we can take a look at what may cause it.
 
Braden Steffaniak
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, heres part of the code that renders what is on the screen every frame.

All of the time things in the thread run method are just to make it only run at 60 fps.



Here is the screen.render(); method:



and here is the renderUser(); method:



Its a bit confusing without seeing the whole code, but I'm trying to condense it a little bit. :/

Thanks for the welcome!
 
Stephan van Hulst
Bartender
Pie
Posts: 5589
54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where's your paintComponent() method? We need to actually see what you are painting.
 
Paul Clapham
Sheriff
Pie
Posts: 20962
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So yeah... you do need to read the Swing concurrency tutorial. For a start I would replace the "60 fps" loop by a javax.swing.Timer object which does the processing at a 1/60-second frequency, but you still need to read the tutorial to find out about the need to make UI changes happen on the Swing event thread.
 
Braden Steffaniak
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:Where's your paintComponent() method? We need to actually see what you are painting.


Yeah... about that... I dont have one. I guess that would be quite important.

Paul Clapham wrote:So yeah... you do need to read the Swing concurrency tutorial. For a start I would replace the "60 fps" loop by a javax.swing.Timer object which does the processing at a 1/60-second frequency, but you still need to read the tutorial to find out about the need to make UI changes happen on the Swing event thread.


And this too, I have known to do this, just to lazy to learn it. I think I will go learn about it right now.
 
Stephan van Hulst
Bartender
Pie
Posts: 5589
54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So.... how do you render your stuff to screen?
 
Braden Steffaniak
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:So.... how do you render your stuff to screen?


What I was doing was adding it to the main frame, then updating the location repeatedly.
 
Rohit Garg
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as my knowledge of graphics goes, you need to look at something called framebuffer. 60 fps is not something that you would just plainly go and loop-update the screen.

Never tried framebuffer myself in swing, but i think it can be the solution to your problem.
 
Braden Steffaniak
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fortunately, All I had to do was the paintComponent method for it to work. Finally it works without flickering! Thanks guys!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic