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