• 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

How to stop graphics from disappearing?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a JPanel in a JFrame and in the panel I can draw a continuous line by pressing buttons, but whenever I resize the window, the lines disappear. How can I stop this?
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kristo,

Welcome to JavaRanch!

You have to save the line in some form as you draw it, and then just paint it in your paintComponent() method(). This method will be called as necessary to redraw the line. So, for example, each time you press a button, you might add a set of coordinates to an array. The paintComponent() method would read all those coordinates from the array and draw the line. Every time it's called it can redraw the whole line.
 
reply
    Bookmark Topic Watch Topic
  • New Topic