title: Trying to embed vlcj media player in a WindowsCanvas inside a JPanel
body: <p>I'm trying to play a video using vlcj inside a JPanel but it doesn't work for me. The message exception I am getting is "java.lang.IllegalStateException: The video surface component must be displayable" which is the same problem as in <a href="https://stackoverflow.com/questions/4830567/keep-getting-an-error-component-must-be-displayable">Keep getting an Error &quot;Component must be displayable&quot;</a>.</p>
  
  <p>The code of the JPanel which contains the canvas and the vlcj player is this:</p>
  
  <pre><code>import javax.swing.JPanel;
  
  import com.sun.jna.Native;
  import com.sun.jna.NativeLibrary;
  
  import java.awt.Canvas;
  import java.awt.Color;
  
  import uk.co.caprica.vlcj.binding.LibVlc;
  import uk.co.caprica.vlcj.player.MediaPlayerFactory;
  import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
  import uk.co.caprica.vlcj.player.embedded.videosurface.CanvasVideoSurface;
  import uk.co.caprica.vlcj.runtime.RuntimeUtil;
  import uk.co.caprica.vlcj.runtime.windows.WindowsCanvas;
  
  public class MyJPanel extends JPanel {
  private EmbeddedMediaPlayer player;
  private WindowsCanvas canvas;
  
  public MyJPanel() {
      canvas = new WindowsCanvas();
      add(canvas);
      revalidate();
      repaint();
  
      canvas.setVisible(true);
  
      MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory();
      player = mediaPlayerFactory.newEmbeddedMediaPlayer();
  
      CanvasVideoSurface videoSurface = mediaPlayerFactory.newVideoSurface(canvas);
  
      player.setVideoSurface(videoSurface);
      player.playMedia("v.avi");   // This sentence throws the exception.
  }
  }
  </code></pre>
  
  <p>MyJFrame extends JFrame and only contains the MyJPanel JPanel. I think it's not important at all.</p>
  
  <pre><code>import javax.swing.JFrame;
  
  public class MyJFrame extends JFrame {
  protected MyJPanel myJPanel;
  
  public static void main(String[] args) {
      EventQueue.invokeLater(new Runnable() {
          public void run() {
              try {
                  MyJFrame frame = new MyJFrame();
                  frame.setVisible(true);
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      });
  }
  
  public MyJFrame() {
      myJPanel = new myJPanel();
      add(myJPanel);
  }   
  }
  </code></pre>
  
  <p>Thanks in advance.</p>