repaint() Method in Java

36,271

Solution 1

It's never really necessary in most swing applications, because they handle it automatically (for common operations such as changing text values on buttons and adding data to a list box).

Generally, it's only if you've made some sort of change that swing won't automatically pick up - for example, you're not using a layout manager and are resizing components manually (because normally the layout manager repaints its components when necessary).

Solution 2

The repaint() refreshes the view (component), so whenever you make any change on the component, you must call it. For instance, if you rotate the graphical component, you must make a call to repaint() in order to see the change on the containing component

Share:
36,271
stk1234
Author by

stk1234

Updated on September 13, 2020

Comments

  • stk1234
    stk1234 over 3 years

    I am playing around with the Java graphics class a little bit and I was just wondering--when is it necessary to call the method repaint()? I tried commenting it out and it didn't seem to affect my output GUI. I've seen it used a lot in Java GUI code that I've read, though. Would anyone mind explaining when to use it and when not to use it?