2012-06-30 74 views
3

我加載的第一個階段總是以全屏方式正常打開。全屏幕舞臺在JavaFX 2.1中無法正常工作?

stage.setFullScreen(true); 
stage.setScene(login_scene); 

但是,當我改變到另一個FXML應用撐全屏(無頂部的工具欄。),但實際觀看內容被調整大小從FXML根AnchorPane的其中prefWidth/prefHeight(我可以看到桌面在我的右下角:|),我希望它對我的屏幕分辨率是動態的。

謝謝。

@Later編輯:

所以在我的主類的start方法我打開一個場景(從FXML文檔中創建),並將其設置爲舞臺(start方法PARAM)。我保存這個階段供以後使用。代碼從主開始重寫方法 -

http://tinypic.com/r/2079nqb/6 - 第一現場正常工作:

當我按下同臺的按鈕我以前保存更改的場景到另一個場景FXML文件

@Screenshots類

@Override 
    public void start(Stage stage) throws Exception { 
    Parent root = FXMLLoader.load(getClass().getResource("Sample.fxml")); 

    stage.setScene(new Scene(root)); 
    stage.setFullScreen(true); 
    stage.show(); 
    currentStage = stage; 
    } 

http://tinypic.com/r/szfmgz/6 - 重裝第二場景後 - 從樣本控制器類代碼如下

@FXML 
    private void handleButtonAction(ActionEvent event) throws IOException { 
    Parent root = FXMLLoader.load(getClass().getResource("Sample.fxml")); 
    JavaFXApplication12.currentStage.setScene(new Scene(root)); 
    } 
+0

是您的第一階段,初級階段?附上截圖(2種不同情況下的截圖)可能會有所幫助。 –

+0

@UlukBiy ok會上傳 –

+0

@UlukBiy上傳的截圖 - 你可以看看...在短版本,它認爲prefWidth/prefHeight作爲全屏尺寸。如果沒有好的解決方案,你知道我怎麼找出屏幕尺寸? –

回答

5

我不知道真正的原因,但這裏有2個快速解決方法。
handleButtonAction方法:
1)不要創建新的場景只需更換其內容

@FXML 
    private void handleButtonAction(ActionEvent event) throws IOException { 
    Parent root = FXMLLoader.load(getClass().getResource("Sample.fxml")); 
    JavaFXApplication12.currentStage.getScene().setRoot(root); 
    } 

2)如果你真的NEAD創建新場景,然後切換到全屏模式

@FXML 
    private void handleButtonAction(ActionEvent event) throws IOException { 
    Parent root = FXMLLoader.load(getClass().getResource("Sample.fxml")); 
    JavaFXApplication12.currentStage.setScene(new Scene(root)); 
    Platform.runLater(new Runnable() { 
     @Override 
     public void run() { 
      JavaFXApplication12.currentStage.setFullScreen(false); 
      JavaFXApplication12.currentStage.setFullScreen(true); 
     } 
    }); 
    } 
0

如果我正確地知道你的擔憂,那麼你應該使用你的主要階段作爲靜態,或者你可以讓其他控制器通過獲取和設置器來使用它。因此,要加載其他fxmls的相同階段,可以在加載fxml時將其設置爲,並且確保不要創建另一個場景。因爲由於新場景,您調整了實際內容。 所以,你可以使用這個

Main.java

YourController objYourController = loader.getController(); 
objYourController.setDialogStage(primaryStage); 

    YourController 
    public void setMystage(Stage primaryStage) 
    { 
     this.primaryStage= primaryStage; 
     } 

//To load another FXML 
Parent root = FXMLLoader.load(getClass().getResource("Sample.fxml")); 
primaryStage.getScene().setRoot(rootLayout); 


Hope it will help you. 
相關問題