How to repaint GUI after a certain element was removed? <p>I'm making an app where a user would be able to add a button to the screen or remove it (I don't have those options implemented yet). So, for now I'm manually populating it with a for() loop and manually removing one of the buttons. My problem is that after the button has been removed (the removal action in the main()), there's just a blank spot. I want to be able to repaint the screen after I remove one of those buttons. In this example, index 2 (block #3) has been removed, leaving an empty space, where it was before... and I have no idea how to repaint it. I've tried validating or repainting from different places in the program with no success.</p> <p>Here's the code (<strong>P.S.</strong> I'm sure my code is not the most efficient way to accomplish what I'm trying to and I'm using setLayout(null), which is not a preferred method, but for now I'm just trying to learn certain things and then expand on that to better myself and my code):</p> <pre><code>import java.awt.Color; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.LineBorder; class TestApp extends JFrame{ JFrame frame = new JFrame("Test Program"); ArrayList&lt;JButton&gt; grid = new ArrayList&lt;JButton&gt;(); private int w = 14; private static int amount = 102; private static int counter = 0; //Default Constructor (sets up JFrame) TestApp(){ frame.setLayout(null); frame.setPreferredSize(new Dimension(1186, 880)); frame.setDefaultCloseOperation(EXIT_ON_CLOSE); frame.setResizable(false); paintGrid(); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } public void newWindow() { JFrame select_win = new JFrame("Selected Frame"); JPanel select_panel = new JPanel(); select_panel.setPreferredSize(new Dimension(600, 800)); select_panel.setBackground(Color.ORANGE); select_win.add(select_panel); select_win.pack(); select_win.setResizable(false); select_win.setVisible(true); select_win.setLocationRelativeTo(null); } private void paintGrid() { for(int i = 0, y = 4; i &lt; ((amount / w) + (amount % w)); i++, y += 104) { for(int j = 0, x = 4; j &lt; w &amp;&amp; (counter &lt; amount); j++, x += 84) { addBlock(counter, x, y); counter++; } } } //Adds a block private void addBlock(int index, int x, int y){ int height = 100; int width = 80; grid.add(new JButton("counter: " + (counter + 1))); (grid.get(index)).addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { javax.swing.SwingUtilities.invokeLater(new Runnable() { @Override public void run() { newWindow(); } }); } }); (grid.get(index)).setBorder(new LineBorder(Color.BLACK)); (grid.get(index)).setBackground(Color.YELLOW); (grid.get(index)).setVisible(true); (grid.get(index)).setBounds(x, y, width, height); frame.add(grid.get(index)); } //Removes a block private void removeBlock(int index){ frame.remove(grid.get(index)); grid.remove(index); amount--; counter--; } public static void main(String [] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { @Override public void run() { TestApp app = new TestApp(); //testing block removal app.removeBlock(2); } }); } } </code></pre>