This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How to stop graphics from disappearing? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to stop graphics from disappearing?" Watch "How to stop graphics from disappearing?" New topic
Author

How to stop graphics from disappearing?

Kristo Liiva
Greenhorn

Joined: Oct 30, 2009
Posts: 4
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?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

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.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to stop graphics from disappearing?
 
Similar Threads
simple web browser in java
Starting and Stopping the Server (RMI)
Question thread
script not stops
How to kill a user thread forcefully?