Я считаю, что обнаружил ошибку с BorderPane. Сцена будет закрыта, как ожидается, если вы не повернете телефон. Однако, если вы повернете телефон и затем нажмите «Закрыть», экран ничего не делает, пока вы не вернете телефон обратно в исходное положение, а затем отобразите primaryStage. Код для его воссоздания очень прост.Этап не будет закрыт с помощью BorderPane после поворота телефона. 90 градусов
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();
}
}
Какой телефон? Возможно, вам захочется предоставить дополнительную информацию о том, как вы протестировали это. Какая бы проблема ни была, вряд ли это будет ошибкой в BorderPane, как вы предлагаете в вопросе. – jewelsea
Производитель: LG Модель: LGMS330 Версия аппаратного обеспечения: Версия 1.0 – user1230989
Версия для Android: 5.1.1 Уровень патча 2015-12-01 Версия ядра 3.10.49 – user1230989