title: Swing Java repaint not working using 2 jpanels
body: <p>As you can see from the code I am expecting to see a rectangle on DrawingPanel but I am not sure why repaint() method is not working. Any help will be much appreciated. I also tried revalidate method but that is not working either. </p>
  
  <p>Here are my Classes:</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  
  public class Designer extends JFrame {
  
  static JFrame f = new Designer();
  
  JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
  DrawingPanel drawingPanel = new DrawingPanel();
  PropertyPanel propertyPanel = new PropertyPanel();
  
   public Designer(){
  
      Rectangle bounds = GraphicsEnvironment
              .getLocalGraphicsEnvironment()
              .getMaximumWindowBounds();
  
      splitPane.setTopComponent(propertyPanel);
      splitPane.setBottomComponent(drawingPanel);
  
      add(splitPane, BorderLayout.CENTER);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setBounds(bounds);
      setVisible(true);
  
   }
  
   public static void main(String[] args) {
      System.out.println("App started...");
   }
  }
  </code></pre>
  
  <p>Class for first Jpanel: <strong>PropertyPanel.Java</strong></p>
  
  <pre><code>import javax.swing.*;
  import java.awt.event.*;
  
  public class PropertyPanel extends JPanel {
  
    private DrawingPanel drawingPanel = new DrawingPanel();
  
    public PropertyPanel(){
  
      JButton addShapesBtn = new JButton("Add");
  
      addShapesBtn.addActionListener(new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
              drawingPanel.addRectangle();
          }
      });
      add(addShapesBtn);
    }
  
  }
  </code></pre>
  
  <p>Class for second Jpanel: <strong>DrawingPanel.Java</strong></p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  import java.util.ArrayList;
  import java.util.List;
  
  public class DrawingPanel extends JPanel{
  
    private List&lt;Rectangle&gt; squares = new ArrayList&lt;Rectangle&gt;();
  
  
   @Override
   protected void paintComponent(Graphics g) {
      super.paintComponent(g);
  
      Graphics2D g2 = (Graphics2D) g;
  
      System.out.println("painting");
  
      for (Rectangle rect : squares) {
          g2.draw(rect);
      }
  
  }
  
  
    public void addRectangle() {
  
      Rectangle rectx = new Rectangle(10, 10, 100, 100);
      squares.add(rectx);
      repaint(); &lt;-- this is not working
    }
  }
  </code></pre>