title: Javafx onMouseclicked
body: <p>I have a main class that sets the scene and stage </p>
  
  <pre><code>public class MediaPlayer extends Application {
  
      public static void main(String[] args) {
          launch(args);
      }
  
      @Override
      public void start(Stage stage) throws Exception {
          Parent root = FXMLLoader.load(getClass().getResource("Main-UI.fxml"));
          stage.setTitle("Media Player");
          stage.setScene(new Scene(root));
          stage.show();
      }
  }
  </code></pre>
  
  <p>I also have a controller class where i implement all most my function and ect . For some reason my setOnMouseClicked do not seem to work. Is this because it is not the same file that calls the stage.show()</p>
  
  <p>Here is an example of the function the mouse event does not work.</p>
  
  <pre><code>private void setMediaViews(){
          String path = "E:" + File.separator + "Videos" +  File.separator + "UFC.205.PPV.Alvarez.vs.McGregor.HDTV.x264-Ebi.mp4";
  
          media = new Media(new File(path).toURI().toString());
          player = new MediaPlayer(media);
          view = new MediaView(player);
          VBox vbox = new VBox();
          Slider slider = new Slider();
          vbox.getChildren().add(slider);
  
          videoMediaCont.setCenter(view);
          videoMediaCont.setBottom(vbox);
  
          player.play();
  
          player.setOnReady(new Runnable() {
              @Override
              public void run() {
                  int w = player.getMedia().getWidth();
                  int h = player.getMedia().getHeight();
  
  
                  view.setFitWidth(900);
                  vbox.setAlignment(Pos.CENTER);
                  vbox.setMinHeight(50);
  
                  slider.setMaxSize(900,50);
                  slider.setMin(0.0);
                  slider.setValue(0.0);
                  slider.setMax(player.getTotalDuration().toSeconds());
                  slider.setOnMouseClicked(new EventHandler&lt;MouseEvent&gt;() {
                      @Override
                      public void handle(MouseEvent event) {
                          player.seek(Duration.seconds(slider.getValue()));
                      }
  
                  });
  
              }
          });
  
          player.currentTimeProperty().addListener(new ChangeListener&lt;Duration&gt;() {
              @Override
              public void changed(ObservableValue&lt;? extends Duration&gt; observable, Duration oldValue, Duration current) {
                  slider.setValue(current.toSeconds());
              }
          });
  
  
      }
  </code></pre>
  
  <p>Any help would be great thank you. </p>