/** * Creates new webcam panel which display image from camera in you your * Swing application. If panel size argument is null, then image size will * be used. If you would like to fill panel area with image even if its size * is different, then you can use {@link #setFillArea(boolean)) method to * configure this. * * @param webcam the webcam to be used to fetch images * @param size the size of panel * @param start true if webcam shall be automatically started * @see WebcamPanel#setFillArea(boolean) */ public WebcamPanel(Webcam webcam, Dimension size, boolean start) { if (webcam == null) { throw new IllegalArgumentException( String.format( "Webcam argument in %s constructor cannot be null!", getClass().getSimpleName())); } this.webcam = webcam; this.webcam.addWebcamListener(this); repainter.setName(String.format("%s-repainter", webcam.getName())); if (size == null) { setPreferredSize(webcam.getViewSize()); } else { setPreferredSize(size); } if (start) { if (!webcam.isOpen()) { webcam.open(); } repainter.start(); } }