paint() belongs to the frame. the first version of this program was a homework assignment in 2004. back then i(we) used to extend JFrame for our main GUI class. i never thought about overriding paint() until this need arose. myself i like it. it is better than having
in 3 different places isn't it?
Joined: Jun 09, 2003
> myself i like it. it is better than having .... in 3 different places isn't it?
have a read of this current thread (just a few below this thread on main page)
Darryl, thanks for your reply. that was exactly what i wanted: almost
i had a gut feeling there was a simpler way than repeating code(almost always a sign of a poor coding), or calling a very short private method from several spots.
there is still a problem though. when i get an image, say by opening a file, if the image is too large there are no scrollbars until i change the size of the frame(even a tiny bit). any ideas about how to fix this?
and please don't anyone change the subject to why i give the one class package access to a variable in another class. it is by choice.
and michael, i actually agree with your point. that is why i posted the question in the first place.
P.S. for the curious, there are 3 way the image can be too large. they are all menu choices. file/open, edit/paste, and image/scale(if you scale it to be bigger).
i thought for a minute i had figured it out. in the action performed for 2 of the possibilities i called a private method that the last line was to repaint the panel. i changed it to repaint the frame but to no avail. i was suspicious this would not work because the third one repainted the frame at the end but still no scrollbars. i will post a little more code from the main class in case it helps.
you didn't read my response closely enough. i called the revaliadate method of the frame and it did not work.
as it turns out when i called the revalidate method of the panel(canvas.revalidate();) , now it does work
thanks so much Darryl! now the code is where it belongs: in getPreferredSize()
and i learned about the revalidate method