• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problems with repainting  RSS feed

 
Alfonso Moreno
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I'm rather new to java programming (especially to Swing).
I'm writing an application that draws level curves on a JPanel. As far as I know, I must then redefine the JPanel.paintComponent so that it repaints itself with the lines I have drawn. But in my case, I have thousands of lines to be repainted, causing a lot of flickering.
Is it any workaround to this?
Using my poor programming mind, created through years of using poor languages, I thought of taking a 'snapshot' of the JPanel with all the lines drawn, and then use drawImage in JPanel.paintComponent, which I suppose to be faster, but I don't know how to do it.
Any suggestion will be appreciated
Thanks in advance
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are on the right track! The 'snapshot' class you are looking for is BufferedImage. Just create a BufferedImage and draw the lines to it once, then paint the BufferedImage in the paintComponent() method, just like you said.
 
Alfonso Moreno
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
THANKS SO MUCH!!!
It worked great. I am recovering my faith in Swing
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!