• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Swing Application Flickering?

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where's your paintComponent() method? We need to actually see what you are painting.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic