1.input_panel background is not set
2.while resizing window sometimes random lines are drawn on the input panel but are not written
either to the database or the file.
3.on starting the paint on the input panel an image of the JMenuBar is created on the input panel.
N.B. output_panel does not show these problems before paintComponent() is overridden, but does oven overriding is done.
Actually I tried that too earlier. The thing is, my input panel is supposed to paint a curve through the points
where i drag my mouse. And those curves must persist for the whole session.
You are right about super.paintComponent(), it does remove those problems but my paintings don't
persist then, instead only the last line drawn remains.
It's not easy to say since we can't compile and run your code. I suggest that you create a much smaller program that just demonstrates an essential part of your program that is not working right, code that is compilable and runnable by us without need for outside classes or resources (such as a database), and this way we can better try to work with you and help you solve your problem.
Oh, and one other thing, you may wish to create an ArrayList<java.awt.Point>, and use your MouseListener to save points to this ArrayList. Then in the paintComponent method, you would draw your curve by iterating through the ArrayList.
One approach is to do the drawing "in memory". Create a BufferedImage the same size as the panel, and draw the background on it. Draw the curve into that. Then, in paintComponent, just copy that image onto the panel. That will usually give you a smoother effect than redrawing the whole curve every time.
Thank you all for the suggestions.
I read through the methods, and though the will solve some of my problems but they add a few too.
As it seems to me, they will add additional overhead.But my application needs to be efficient as the user needs the see the
handwritten characters as he/she writes them and the document can be quite lengthy.
Repainting all the points from the beginning ,is required by both the processes.
The problem is arising due to overriding paintComponent().
Is there any other way in swing,like the one done in awt where overriding update() causes incremental painting??
Somewhere it said if super.paintComponent() is not called,then the application must take care of the functions like
setBackground(), etc. How do I do that??
parvez ali wrote:
As it seems to me, they will add additional overhead.But my application needs to be efficient as the user needs the see the
handwritten characters as he/she writes them and the document can be quite lengthy.
Repainting all the points from the beginning ,is required by both the processes.
The problem is arising due to overriding paintComponent().
Is there any other way in swing,like the one done in awt where overriding update() causes incremental painting??
Somewhere it said if super.paintComponent() is not called,then the application must take care of the functions like
setBackground(), etc. How do I do that??
greatly appreciate all of your time and effort.
Matthew and Rob both referred to solutions for this -- use a BufferedImage and draw to it. Shoot you can mix the solutions where any background image is placed in a BufferedImage, and any animation in the paintComponent (well, the BufferedImage is painted in the paintComponent too). Also, you will need to look at the overloads for the repaint method to limit the rectangle that requires repainting.
Hello friends, I finally came to the conclusion that there is no other way
than to redraw the whole set of pixel each time, like you all suggested me.
But since i was already using a database,i decided to use the data stored over there
instead of creating arraylists,bufferedimage etc.
The overhead is hardly noticeable.
parvez ali wrote:Hello friends, I finally came to the conclusion that there is no other way
than to redraw the whole set of pixel each time, like you all suggested me.
I thought that we were clear that we aren't suggesting this. If any of our posts are confusing, please ask for clarification.
But since i was already using a database,i decided to use the data stored over there
instead of creating arraylists,bufferedimage etc.
The overhead is hardly noticeable.
Just be sure that all database accessing is not done on Swing's event thread, the EDT.