repaint problem in java swing
Hi friends,
i am making a graphical user interface of drawing different process modelling.but problem is that in the editior after the drawing of one digram(like rectangle) and when draw the second one(circle),the first has been(rectangle) disappeared due to repaint method.
so give me some idea about ,how to come over that and i want to use mysql as database so as to store the information about the digram.
Re: repaint problem in java swing
Hi,
please be more specific on how you set it up.
what I understand is that you paint both the items in the frame?
but not in the paint event of the object?
it's better to perform all the painting in the paint event of the object.
let me know,
Jewe
Re: repaint problem in java swing
It is because you probably only have one reference to a diagram object and you are overwriting it when you draw a new one. With this method you can draw a square, then draw a circle, then draw whatever but if you move/resize the container or minimize maximize it then you invalidate the graphics area you were drawing on and an entire repaint request happens, for which you only have the last diagram object to repaint with.
If you want to keep the rectangle after you draw the circle then you need to store the rectangle and the circle and whatever else comes next in a collection like an ArrayList. Then in your paint method you will iterate through this collection and draw each diagram object onto the canvas.