title: Transparent JPanel over Canvas (VLCJ)
body: <p>I know that a similar question was <a href="https://stackoverflow.com/questions/2282454/add-transparent-jpanel-upon-awt-component-to-paint-on">posted before</a>, but there was no answer or example code.</p>
  
  <p>I need a transparent JPanel on top of a canvas. The code posted below is not working</p>
  
  <pre><code>import java.awt.BorderLayout;
  import java.awt.Canvas;
  import java.awt.Color;
  import java.awt.Graphics;
  import javax.swing.JFrame;
  import javax.swing.JLayeredPane;
  import javax.swing.JPanel;
  
  public class Main {
      private static class Background extends Canvas{
          @Override
          public void paint(Graphics g) {
              super.paint(g);
              g.setColor(Color.RED);
              g.drawOval(10, 10, 20, 20);
          }
      }
  
      private static class Transparent extends JPanel {
  
          public Transparent() {
              setOpaque(false);
          }
  
          @Override
          protected void paintComponent(Graphics g) {
              super.paintComponent(g);
              g.setColor(Color.GREEN);
              g.drawOval(20, 20, 20, 20);
          }
      }
  
      public static void main(String[] args){
          JFrame frame = new JFrame();
          JLayeredPane layered = new JLayeredPane();
          Background b = new Background();
          Transparent t = new Transparent();
  
          layered.setSize(200, 200);
          b.setSize(200, 200);
          t.setSize(200, 200);
  
          layered.setLayout(new BorderLayout());
          layered.add(b, BorderLayout.CENTER, 1);
          layered.add(t, BorderLayout.CENTER, 0);
  
          frame.setLayout(new BorderLayout());
          frame.add(layered, BorderLayout.CENTER);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(200, 200);
          frame.setVisible(true);
      }
  }
  </code></pre>
  
  <p>Using the GlassPane property of the entire frame is the very last solution (highly discouraged)</p>