2016-05-23 30 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已經有了自己的對話框,更適合於移動環境。