Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在javafx中重新加载场景时,“最大化”不起作用_Java_Javafx - Fatal编程技术网

在javafx中重新加载场景时,“最大化”不起作用

在javafx中重新加载场景时,“最大化”不起作用,java,javafx,Java,Javafx,请帮帮我。 我有以下代码 public class Main extends Application { private static Locale locale = new Locale("de", "DE"); private Scene scene; public static Stage stage; @Override public void start(Stage primaryStage) throws Exception { s

请帮帮我。 我有以下代码

public class Main extends Application {

    private static Locale locale = new Locale("de", "DE");
    private Scene scene;
    public static Stage stage;

@Override
    public void start(Stage primaryStage) throws Exception {
        stage = primaryStage;

        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("FXMLDocument.fxml"));
        ResourceBundle bundle = ResourceBundle.getBundle("bundles.lang", locale);
        fxmlLoader.setResources(bundle);

        Parent root = fxmlLoader.load();

        scene = new Scene(root);
        stage.setMaximized(true);
        stage.setScene(scene);

            stage.show();
}
    public void reload() throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("FXMLDocument.fxml"));
        fxmlLoader.setResources(ResourceBundle.getBundle("bundles.lang", locale));

        Parent root = fxmlLoader.load();

        scene = new Scene(root);
        stage.setMaximized(true);
        stage.setScene(scene);

        stage.show();

    }
}
在我的控制器类中

public class FXMLDocumentController implements Initializable {
@FXML
    AnchorPane root;

    @FXML
    private void handleChinese(final ActionEvent event) throws IOException {

        Main.setLocale(new Locale("zh", "CN")); // change to english
        //JavaFXApplication4.stage.close();
        Main reload = new Main();
        reload.reload();
    }

    @FXML
    private void handleRussian(final ActionEvent event) throws IOException {

        Main.setLocale(new Locale("de", "DE")); // change to english
        Main reload = new Main();
        reload.reload();
    }
它起作用了!,但是当更改语言时,我的窗口没有正确显示,这意味着
stage.setMaximized(true)
没有工作,我的窗口没有显示为Maximized


为什么
stage.setMaximized(true)
不能正常工作?

只需将root设置为前一个场景,而不是创建新场景

public void reload() throws IOException {
    FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("FXMLDocument.fxml")); 
    Parent root = fxmlLoader.load();
    stage.getScene().setRoot(root);
//        Scene scene = new Scene(root);
//        stage.setMaximized(true);
//        stage.setScene(scene);
//
//        stage.show();
}

您的FXMLDocument看起来如何?