E
E
Elfino482016-08-22 15:00:24
Java
Elfino48, 2016-08-22 15:00:24

Why does everything drawn on the frame disappear when the window is minimized?

I made a mini-drawer (on the first two mouse clicks a line is created, on the rest it turns into a polyline, etc. + when you click on one of the existing points, the polyline "closes"), but a problem popped up: draw yourself, draw, minimize the window, unfold - and it's all erased. Tell me how to fix it?
before folding:
743a7ef16cb84fd49e72d35acd0e0132.jpgafter:
91e2643254514afb994895cbaf41e4ee.jpg
If necessary, I will throw the entire code of the program

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Fat Lorrie, 2016-08-22
@Free_ze

Because the contents of the window are redrawn when minimized, obscured by another window, resized, etc. You need to store your creativity in memory and redraw during the window redraw event.

public class MyPanel extends JPanel {
    public void paint(Graphics g) {
        // do your painting here
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question