1

BorderPane でバグを見つけたと思います。電話を回転させなければ、ステージは期待どおりに閉じます。ただし、電話を回転させて [閉じる] をクリックすると、電話を元の位置に戻すまで画面に何も表示されず、primaryStage が表示されます。それを再現するコードは非常に単純です。

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.FlowPane;
import javafx.stage.Modality;
import javafx.stage.Screen;
import javafx.stage.Stage;

public class HelloWorld extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Hello World!");
        Button btn = new Button();
        btn.setText("Say 'Hello World'");
        btn.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent event) {
                final Stage stage = new Stage();

                Button closeBtn = new Button("Close");
                closeBtn.setOnAction(new EventHandler<ActionEvent>() {
                    @Override
                    public void handle(ActionEvent event) {
                        stage.close();
                    }
                });
                FlowPane pane = new FlowPane();
                pane.getChildren().addAll(new Label("Hello World!"), closeBtn);
                Scene scene = new Scene(pane);
                stage.initModality(Modality.APPLICATION_MODAL);
                stage.initOwner(primaryStage);
                stage.setScene(scene);
                stage.show();
            }
        });

        BorderPane borderPane = new BorderPane();
        borderPane.setPrefHeight(Screen.getPrimary().getVisualBounds().getMaxY());
        borderPane.setPrefWidth(Screen.getPrimary().getVisualBounds().getMaxX());
        borderPane.setCenter(btn);

        primaryStage.setScene(new Scene(borderPane));
        primaryStage.show();
    }

この問題を回避する方法を知っている人はいますか?

build.gradle

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'org.javafxports:jfxmobile-plugin:1.0.8'
    }
}

apply plugin: 'org.javafxports.jfxmobile'

mainClassName = 'helloworld.HelloWorld'
version = '8u40'

repositories {
    mavenLocal()
    mavenCentral()
    jcenter()
}

jfxmobile {
    ios {
    forceLinkClasses = ['ensemble.**.*']
    }
    android {
    applicationPackage = 'org.javafxports.ensemble'
    }
}

ヒントをありがとう。余分なステージとシーンを削除しました。私の回避策はこれです。

package helloworld;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.FlowPane;
import javafx.stage.Screen;
import javafx.stage.Stage;

public class HelloWorld extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Hello World!");

        final Group group = new Group();

        final BorderPane borderPane = new BorderPane();
        borderPane.setPrefHeight(Screen.getPrimary().getVisualBounds().getMaxY());
        borderPane.setPrefWidth(Screen.getPrimary().getVisualBounds().getMaxX());

        final Button btn = new Button("Say 'Hello World'");
        borderPane.setCenter(btn);
        btn.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent event) {
                Button closeBtn = new Button("Close");
                closeBtn.setOnAction(new EventHandler<ActionEvent>() {
                    @Override
                    public void handle(ActionEvent event) {
                        group.getChildren().setAll(borderPane);
                    }
                });
                FlowPane pane = new FlowPane();
                pane.getChildren().addAll(new Label("Hello World!"), closeBtn);
                group.getChildren().setAll(pane);
            }
        });

        group.getChildren().add(borderPane);

        primaryStage.setScene(new Scene(group));
        primaryStage.show();
    }
}
4

1 に答える 1