how to remove components from a JFRame java

Java
 private JFrame frame = new JFrame();
 ...
 ...
 frame.getContentPane().removeAll();
 frame.repaint();
Source

Also in Java: