wood burning stoves*
The moose likes Performance and the fly likes Swing Application Flickering? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "Swing Application Flickering?" Watch "Swing Application Flickering?" New topic
Author

Swing Application Flickering?

Braden Steffaniak
Greenhorn

Joined: Jun 03, 2011
Posts: 15
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Sep 20, 2010
Posts: 3615
    
  14

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

Joined: Jun 03, 2011
Posts: 15
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

Joined: Sep 20, 2010
Posts: 3615
    
  14

Where's your paintComponent() method? We need to actually see what you are painting.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Jun 03, 2011
Posts: 15
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

Joined: Sep 20, 2010
Posts: 3615
    
  14

So.... how do you render your stuff to screen?
Braden Steffaniak
Greenhorn

Joined: Jun 03, 2011
Posts: 15
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

Joined: Feb 05, 2008
Posts: 30
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.


Regards,
Rohit.
Braden Steffaniak
Greenhorn

Joined: Jun 03, 2011
Posts: 15
Fortunately, All I had to do was the paintComponent method for it to work. Finally it works without flickering! Thanks guys!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Swing Application Flickering?