I have created a class that extends JPanel and have passed a Graphics object to its paintComponent method which draws a couple of shapes onto it, and added it to a JFrame object. I have set this frame's size and made it visible.
All works fine except for the shape sliding more and more out of view (down and right) every time I resize the window at runtime.
Would be great if you could point me to some JFrame method or something that could make these elements stay in their initial position in the frame, regardless of window size.
posted 6 years ago
Oh my, I just realized that this was due to incremental operators left in drawRect's parameter from previous experimentation. So, to answer my own silly little question, the paintComponent method is called every time the window is resized. Lesson learned. If answering your own question is considered a bit silly, I won't sadden me if you remove it, but maybe someone'll find it useful.
and no, don't feel bad about it. often just formulating the question so others can understand it gives you the clue you need to solve it. i am probably the worst person here for this. i get frustrated, ask a question, take a brak and come back and say "oh, never mind i figured it out". but please give the solution when you do this