我相信我发现了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();
}
}
答案 0 :(得分:0)
虽然我可以重现您的问题,并且您可以报告here,但移动设备上的内容与桌面有点不同,您不应该创建不同的舞台或不同的场景:只需切换而是场景中的节点。
如果您使用Gluon的插件创建项目,您会注意到它使用View
个节点,您可以轻松地在它们之间切换,但始终与相同的根相关联({{1在同一个场景上。
如果你需要对话框,你可以使用JavaFX内置的Dialogs,但是Gluon已经有了自己的对话框,更适合移动环境。