title: Set JPanel background transparent, setOpaque() doesn't let me paint
body: <pre><code>import java.awt.Color;
  import java.awt.Font;
  import java.awt.Graphics;
  import java.awt.GridBagConstraints;
  import java.awt.GridBagLayout;
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  
  public class Tetris extends JFrame {
  
  public Tetris() {
  
      add(new GamePanel());
      setDefaultCloseOperation(EXIT_ON_CLOSE);
      setResizable(false);
      setSize(800, 600);
      setVisible(true);
      setLocationRelativeTo(null);
      setTitle("Tetris");
  }
  
  public class GamePanel extends JPanel {
  
  
      public GamePanel(){
          TetrisBoard tetraBoard= new TetrisBoard();
          GridBagLayout layout= new GridBagLayout();
          this.setLayout(layout);
          GridBagConstraints c = new GridBagConstraints();
          c.gridx = 2;
          c.gridy = 1;
          c.ipadx = 190;
          c.ipady = 390;
          c.insets.left= 360;
          layout.setConstraints(tetraBoard, c);
          this.add(tetraBoard);
          setBackground(Color.WHITE);
      }
  
     @Override
     public void paint(Graphics g){
         super.paint(g);
  
         g.setFont(new Font("Birth Std", Font.PLAIN, 12));
         g.setColor(Color.LIGHT_GRAY);
         g.drawString("200", 36, 63);
         g.drawString("200", 36, 88);
         g.drawString("200", 36, 114);
      }
  
  }//GamePanel class
  
  public class TetrisBoard extends JPanel implements Runnable{
      private Thread animator= new Thread(this);
      private final int DELAY= 50;
  
      public TetrisBoard(){
          setFocusable(true);
          //setBackground(Color.WHITE);
          setDoubleBuffered(true);
          //this.setBackground(Color.BLACK);
          setOpaque(false);
      }
  
      @Override
      public void addNotify() {
      super.addNotify();
          animator = new Thread(this);
          animator.start();
      }//addNotify
  
  
     @Override
     public void paint (Graphics g){
         super.paint(g);
         g.drawRect (20, 30, 130, 50);
  
     }//paint
  
     @Override
  public void run() {
      long beforeTime, timeDiff, sleep;
  
      beforeTime = System.currentTimeMillis();
  
      while (true) {
          repaint();
  
          timeDiff = System.currentTimeMillis() - beforeTime;
          sleep = DELAY - timeDiff;
  
          if (sleep &lt; 0)
              sleep = 2;
          try {
              Thread.sleep(sleep);
          } catch (InterruptedException e) {
              System.out.println("interrupted");
          }
  
          beforeTime = System.currentTimeMillis();
      }
  } 
  
  }//TetrisBoard class
  
  
  public static void main(String[] args) {
      Tetris t = new Tetris();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>With this code the result is that it doesn't paint anything at all. I just want the background to be transparent not the images painted over the background, but it looks like the paint method doesn't paint if I setOpaque(false).</p>
  
  <p>Edit: as requested I posted a simple code, TetraBoard is added to the GamePanel (using that GridBagLayout), and GamePanel is added to the frame, those 3 classes are separate files. I want TetraBoard to have a transparent background, so that I can see the background of GamePanel, but what I paint on tetraboard must be visible. If I setOpaque(false), TetraBoard is transparent, but it set on transparent everything I paint on it.</p>