title: How do you make it so that a button doesn't interfere with the location of drawn shape?
body: <p>So basically when I add a button it essentially pushes the black rectangle drawn in this program down, putting it out of its given location. How would you fix this?</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  
  public class Grid {
  
      public class homeGraphics extends JComponent {
          homeGraphics() {
              setPreferredSize(new Dimension(450, 600));
          }
  
          public void paint(Graphics g) {
              super.paint(g);
              g.fillRect(200, 275, 50, 50);
          }
      }
  
      public void homeFrame() {
          JFrame frame1 = new JFrame();
          frame1.setSize(450, 600);
          frame1.setResizable(false);
          frame1.setDefaultCloseOperation(frame1.EXIT_ON_CLOSE);
  
          JButton playButton = new JButton("Play");
          playButton.setPreferredSize(new Dimension(60, 30));
  
          JPanel panel1 = new JPanel();
          panel1.add(playButton);
          panel1.add(new homeGraphics());
  
          frame1.add(panel1);
          frame1.setVisible(true);
      }
  
      public static void main(String args[]) {
          Grid frame = new Grid();
          frame.homeFrame();
      }
  }```
  </code></pre>