Javafx 手机旋转90度后,后台将不会使用边框窗格关闭
我相信我在BorderPane上发现了一个bug。如果不旋转手机,舞台将按预期关闭。但是,如果您旋转手机,然后单击“关闭”,屏幕将不会执行任何操作,直到您将手机旋转回原始位置,然后显示primaryStage。重新创建它的代码非常简单Javafx 手机旋转90度后,后台将不会使用边框窗格关闭,javafx,gluon,borderpane,Javafx,Gluon,Borderpane,我相信我在BorderPane上发现了一个bug。如果不旋转手机,舞台将按预期关闭。但是,如果您旋转手机,然后单击“关闭”,屏幕将不会执行任何操作,直到您将手机旋转回原始位置,然后显示primaryStage。重新创建它的代码非常简单 import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene;
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();
}
谢谢你的提示。我移除了额外的舞台和场景。我的解决办法是这样
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();
}
}
包helloworld;
导入javafx.application.application;
导入javafx.event.ActionEvent;
导入javafx.event.EventHandler;
导入javafx.scene.Group;
导入javafx.scene.scene;
导入javafx.scene.control.Button;
导入javafx.scene.control.Label;
导入javafx.scene.layout.BorderPane;
导入javafx.scene.layout.FlowPane;
导入javafx.stage.Screen;
导入javafx.stage.stage;
公共类HelloWorld扩展了应用程序{
公共静态void main(字符串[]args){
发射(args);
}
@凌驾
公共无效开始(阶段primaryStage){
setTitle(“你好,世界!”);
最终组=新组();
final BorderPane BorderPane=新的BorderPane();
setPrefHeight(Screen.getPrimary().getVisualBounds().getMaxY());
setPrefWidth(Screen.getPrimary().getVisualBounds().getMaxX());
最终按钮btn=新按钮(“说‘你好世界’”);
边界窗格。设置中心(btn);
btn.setOnAction(新的EventHandler(){
@凌驾
公共无效句柄(ActionEvent事件){
按钮关闭Btn=新按钮(“关闭”);
setOnAction(新的EventHandler(){
@凌驾
公共无效句柄(ActionEvent事件){
group.getChildren().setAll(边框窗格);
}
});
FlowPane=新的FlowPane();
pane.getChildren().addAll(新标签(“Hello World!”),closeBtn);
group.getChildren().setAll(窗格);
}
});
group.getChildren().add(边框窗格);
初级阶段。场景(新场景(组));
primaryStage.show();
}
}
虽然我可以重现您的问题,您也可以报告,但在移动设备上,事情与桌面有点不同,您不应该创建不同的舞台或场景:只需切换场景上的节点即可
如果您使用Gluon的插件创建项目,您会注意到它使用视图
节点,您可以轻松地在它们之间切换,但始终与同一场景中的同一根(GlassPane
)相关
如果您需要对话框,您可以使用JavaFX内置对话框,但Glion已经有了自己的对话框,更适合移动环境。虽然我可以重现您的问题,您可以报告,但在移动设备上,事情与桌面有点不同,您不应该创建不同的舞台或场景:只需切换场景中的节点即可 如果您使用Gluon的插件创建项目,您会注意到它使用
视图
节点,您可以轻松地在它们之间切换,但始终与同一场景中的同一根(GlassPane
)相关
如果您需要对话框,您可以使用JavaFX内置对话框,但Gluon已经有了自己的对话框,更适合移动环境。什么手机?您可能想提供更多关于如何测试此功能的信息。无论问题是什么,它似乎不太可能像您在问题中建议的那样是BorderPane中的错误。Make:LG型号:LGMS330硬件版本:Rev。1.0Android版本:5.1.1补丁级别2015-12-01内核版本3.10.49是否使用JavaFXPorts?您是否正在使用Gluon插件创建项目?你能发布你的
build.gradle
文件吗?什么电话?您可能想提供更多关于如何测试此功能的信息。无论问题是什么,它似乎不太可能像您在问题中建议的那样是BorderPane中的错误。Make:LG型号:LGMS330硬件版本:Rev。1.0Android版本:5.1.1补丁级别2015-12-01内核版本3.10.49是否使用JavaFXPorts?您是否正在使用Gluon插件创建项目?你能发布你的build.gradle
文件吗?
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();
}
}