我相信我发现了 BorderPane 的错误。如果您不旋转手机,舞台将按预期关闭。但是,如果您旋转手机,然后单击关闭,则屏幕不会执行任何操作,直到您将手机旋转回原始位置,然后显示主舞台。重新创建它的代码非常简单。
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();
}
有谁知道如何解决这个问题?
构建.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();
}
}