Briefly, you should use both.
repaint()
alerts Swing that some area of the screen is inappropriate, "dirty". It is necessary to delete the image of old child components removed by removeAll()
for example.
revalidate()
recalculates the layout through the layout manager. Usually used when adding components on the panel. This causes the children components of the panel to "reposition" but not the panel itself.
This method is called specific cases .
Remembering that revalidate()
is calling the invalidate()
method on all container components, which marks them as invalid, and soon after validate()
. This calls the layoutComponents()
method of the layout manager. If a layout change is required, repaint()
is called.