2016-08-08 4 views
2

저는 JavaFX 8의 MultiMedia 클래스를 사용하여 자체 멀티미디어 응용 프로그램을 작성하고 있습니다. 처음부터 (내 시작) 내 프로그램을 실행할 때 너비와 높이가 내 Stage과 같습니다. 미디어 (비디오)의 넓이와 높이.JavaFX MediaPlayer - 스테이지 크기

mp.setOnReady(new Runnable() { 
     @Override 
     public void run() { 
      Timeline slideIn = new Timeline(); 
      Timeline slideOut = new Timeline(); 

      stage.getScene().setOnMouseEntered(e -> { 
       slideIn.play(); 
      }); 

      stage.getScene().setOnMouseExited(e -> { 
       slideOut.play(); 
      }); 
      // here I get the width and heigth of the media 
      int w = mp.getMedia().getWidth(); 
      int h = mp.getMedia().getHeight(); 
      // width is 1280 and heigth is 720 (both values are correct) 
      if (w != 0 && h != 0) { 
       //Here Im setting the width and the height of stage 
       //But when I run my app, stage is a little bit smaller than 
       //MediaView and I have to resize the stage manually by cca 20px to get the whole view 
       stage.setWidth(w); 
       stage.setHeight(h); 
       stage.centerOnScreen(); 

       //On the other hand, animation works pretty well and 
       //correctly with the "w" and "h" 
       mediaBar.setMinSize(w - 100, 100); 
       mediaBar.setTranslateY(h - 100); 
       mediaBar.setTranslateX(50); 
       mediaBar.setOpacity(0); 

       slideIn.getKeyFrames().addAll(new KeyFrame(new Duration(0), new KeyValue(mediaBar.translateYProperty(), h), new KeyValue(mediaBar.opacityProperty(), 0.0)), 
         new KeyFrame(new Duration(300), new KeyValue(mediaBar.translateYProperty(), h - 100), new KeyValue(mediaBar.opacityProperty(), 0.9)) 
       ); 

       slideOut.getKeyFrames().addAll(new KeyFrame(new Duration(0), new KeyValue(mediaBar.translateYProperty(), h - 100), new KeyValue(mediaBar.opacityProperty(), 0.9)), 
         new KeyFrame(new Duration(300), new KeyValue(mediaBar.translateYProperty(), h), new KeyValue(mediaBar.opacityProperty(), 0.0)) 
       ); 

       background.setWidth(w - 100); 
       background.setHeight(100); 
       background.setTranslateY(h - 100); 
       background.setTranslateX(50); 
       background.setOpacity(0); 

       slideIn.getKeyFrames().addAll(new KeyFrame(new Duration(0), new KeyValue(background.translateYProperty(), h), new KeyValue(background.opacityProperty(), 0.0)), 
         new KeyFrame(new Duration(300), new KeyValue(background.translateYProperty(), h - 100), new KeyValue(background.opacityProperty(), 1)) 
       ); 

       slideOut.getKeyFrames().addAll(new KeyFrame(new Duration(0), new KeyValue(background.translateYProperty(), h - 100), new KeyValue(background.opacityProperty(), 1)), 
         new KeyFrame(new Duration(300), new KeyValue(background.translateYProperty(), h), new KeyValue(background.opacityProperty(), 0.0)) 
       ); 
      } else { 
       //music 
      } 
      duration = mp.getMedia().getDuration(); 
      updateValues(); 
     } 
    }); 

그래서 내가 아직 모르는 Stage 클래스에 대해 중요한 것이 있다고 생각합니다.

initStyleStage에서 StageStyle.UNDECORATED으로 설정하면 전체 MediaView을 볼 수 있습니다. 그러나 나는이 스타일을 원하지 않는다.

누구든지이 문제를 해결할 수 있습니까? 이 질문이 처음 도움말 요청이기 때문에 올바르게 문제를 설명했기를 바랍니다. 감사.

답변

0

이것은 스테이지의 높이와 너비가 장식을 포함하기 때문입니다. javadoc of widthProperty에서 :

이 값은 프레임 크기 조정 핸들로 운영 체제에 의해 첨가 될 수있는 모든 장식을 포함한다. 일반적인 응용 프로그램 인 은 장면 너비를 대신 설정합니다.

그리고 해결책은 문서에 나와 있습니다. Scene의 크기를 설정할 수 있습니다.

이 예에서는 크기가 400x400 인 Scene을 포함하는 Stage을 엽니 다. 당신이 SceneStage의 크기 때문에 장식의 더 큰 것으로 표시됩니다 설정하면

public class Main extends Application { 
    @Override 
    public void start(Stage primaryStage) { 
     try { 
      BorderPane root = new BorderPane(); 
      Scene scene = new Scene(root,400,400); 
      primaryStage.setTitle("Stage with 400x400 Scene"); 
      primaryStage.setScene(scene); 

      primaryStage.setOnShown(event -> System.out.println("Size of the Stage is " + primaryStage.getHeight() + "x" + primaryStage.getWidth())); 

      primaryStage.show(); 
     } catch(Exception e) { 
      e.printStackTrace(); 
     } 
    } 

    public static void main(String[] args) { 
     launch(args); 
    } 
} 

출력,

Size of the Stage is 438.0x416.0 

그래서 당신은 볼 수 있습니다.

업데이트 : 그냥 비슷한 답변을 찾았습니다. JavaFX: Set Scene min size excluding decorations

관련 문제