2016-05-23 31 views
1

我相信我发现了一个BorderPane的bug。如果您不旋转手机,舞台将按预期关闭。但是,如果旋转手机,然后单击关闭,则屏幕将不执行任何操作,直到您将手机旋转回原始位置,然后显示primaryStage。重新创建它的代码非常简单。手机旋转90度后舞台不会关闭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(); 
    } 

有没有人知道如何解决这个问题?

的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

什么手机?你可能想提供一些关于你如何测试它的更多信息。无论问题是什么,在你提出的问题中,似乎都不太可能成为BorderPane中的一个bug。 – jewelsea

+0

品牌:LG型号:LGMS330硬件版本:修订版1.0 – user1230989

+0

Android版本:5.1.1补丁级别2015-12-01内核版本3.10.49 – user1230989

回答

0

虽然我可以重现你的问题,你可以进行举报here,移动的东西是从桌面有点不同,你不应该创建一个不同的阶段或者不同的场景:只需切换节点而是在现场。

如果您使用Gluon的插件创建项目,您会注意到它使用了View节点,您可以轻松地在它们之间切换,但始终与同一场景中的同一根(GlassPane)相关。

如果您需要对话框,您可以使用JavaFX内置的对话框,但是Gluon已经有了自己的对话框,更适合于移动环境。