Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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: 27375
88
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: 14325
321
  • 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: 14325
321
  • 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: 27375
88
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: 14325
321
  • 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!
 
I RELEASE YOU! (for now .... ) Feel free to peruse this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic