2012-06-30 77 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. 
相关问题