2016-05-20 53 views
10

Sto lavorando a un'applicazione JavaFX che contiene alcuni file html, css, JS che sono resi dal browser webkit interno. Ora, il problema sono le animazioni CSS che non vengono visualizzate correttamente nel browser webkit fornito da JavaFX, ma lo stesso codice in Firefox o Chrome è piuttosto uniforme.JavaFX: Incorporamento di un browser diverso dalla visualizzazione Web disponibile con JavaFX

Inoltre, non è disponibile la persistenza (le variabili attualmente in uso in Java e la comunicazione tramite JS per la persistenza).

Quello che sto cercando è un modo per integrare un browser senza testa o alcune impostazioni per rendere più fluide le animazioni CSS. L'unica cosa che ho trovato era JxBrowser, ma è toooooo costoso per uso personale.

Codice:

public class Main extends Application { 

    private Scene scene; 
    MyBrowser myBrowser; 

    String completeText = ""; 

    @Override 
    public void start(Stage primaryStage) throws Exception{ 
     primaryStage.setTitle("Frontend"); 
     java.net.CookieManager manager = new java.net.CookieManager(); 
     java.net.CookieHandler.setDefault(manager); 

     myBrowser = new MyBrowser(); 
     scene = new Scene(myBrowser, 1080, 1920); 

     primaryStage.setScene(scene); 
     primaryStage.setFullScreen(true); 
     primaryStage.show(); 

     // @ being the escape character 
     scene.setOnKeyTyped(new EventHandler<KeyEvent>() { 
      @Override 
      public void handle(KeyEvent event) { 
       String text = event.getCharacter(); 
       if (text.equals("0")) { 
        String tempText = completeText; 
        completeText = ""; 
        processText(tempText); 
       }else { 
        completeText = completeText+text; 
       } 
      } 
     }); 
    } 
} 

MyBrowser:

public class MyBrowser extends Region { 

public MyBrowser() { 
     webEngine.getLoadWorker().stateProperty().addListener((observable, oldValue, newValue) -> { 
      if (newValue == Worker.State.SUCCEEDED) { 
       JSObject window = (JSObject) webEngine.executeScript("window"); 
       window.setMember("app", this); 
      } 
     }); 




     URL urlHello = getClass().getResource(hellohtml); 

     webEngine.load(urlHello.toExternalForm()); 
     webView.setPrefSize(1080, 1920); 
     webView.setContextMenuEnabled(false); 
     getChildren().add(webView); 
    } 

codice CSS che contiene l'animazione:

#ball-container.go #ball{ 
-webkit-animation: rotating-inverse 2s ease-out 0s 1 normal; 
animation: rotating-inverse 2s ease-out 0s 1 normal; 
} 


#ball-container { 
height: 102px; 
width: 102px; 
position: absolute; 
top: -95px; 
left: 480px; 
-webkit-transition: all 0.9s ease-in-out 0s; 
transition: all 0.9s ease-in-out 0s; 
} 



#ball-container.shake .ball-wrapper{ 
-webkit-animation: yAxis 0.9s ease-in-out; 
animation: yAxis 0.9s ease-in-out; 
} 

Grazie.

+0

il il codice che hai fornito non viene compilato. Anche l'HTML è mancante. –

+0

@OJKrylow: questo codice è solo per riferimento, una delle animazioni che abbiamo. Puoi provare qualsiasi animazione CSS dalla rete (lo abbiamo già fatto) e le prestazioni sono scadenti. –

+0

Ho testato la WebView con https://daneden.github.io/animate.css/ in modalità 64 bit e 32 bit. Non c'è jank notevole con le animazioni. A parte il fatto che alcuni elementi non vengono visualizzati correttamente, l'animazione sembra soddisfacente. –

risposta

1

Provare a utilizzare Java 8u112, con sede nel codice ho creato un campione di lavoro (testati utilizzando Java JDK 8u112 64bit):

import javafx.application.Application; 
import javafx.scene.Parent; 
import javafx.scene.Scene; 
import javafx.scene.web.WebEngine; 
import javafx.scene.web.WebView; 
import javafx.stage.Stage; 

public class Example extends Application 
{ 
    public static void main(String[] args) 
    { 
     launch(args); 
    } 

    class MyBrowser extends Parent 
    { 
     private WebEngine webEngine; 
     private WebView webView; 

     public MyBrowser() 
     { 
      webView = new WebView(); 
      webEngine = webView.getEngine(); 

      // Ugly (but easy to share) HTML content 
      String pageContents = 
        "<html>" 
         + "<head>" 
          + "<style>" 
           + "@-webkit-keyframes mymove {" 
            + "from {top: 0px;}" 
            + "to {top: 50px;}" 
           + "}" 
           + ".box { " 
            + "width: 150px; " 
            + "position: relative; " 
            + "height: 150px; " 
            + "background: red; " 
            + "margin-top: 35px; " 
            + "margin-left: auto; " 
            + "margin-right: auto; " 
            + "-webkit-transition: background-color 2s ease-out; " 
            + "-webkit-transition: all 1s ease-in-out; " 
           + "}" 
           +".box:hover {" 
            +" background-color: green;" 
            + "width:350px;" 
            + "-webkit-animation: mymove 1s infinite;" 
           +"}"   
          + "</style>" 
         + "</head>" 
         + "<body>" 
          + "<div class='box'></div>" 
         + "</body>" 
        + "</html>"; 

      webEngine.loadContent(pageContents); 
      webView.setContextMenuEnabled(false); 
      getChildren().add(webView); 
     } 
    } 

    private Scene scene; 
    MyBrowser  myBrowser; 

    @Override 
    public void start(Stage primaryStage) throws Exception 
    { 
     primaryStage.setTitle("Frontend"); 
     myBrowser = new MyBrowser(); 
     scene = new Scene(myBrowser); 
     primaryStage.setScene(scene); 
     primaryStage.show(); 
    } 
} 

ho il sospetto che questo è perché sono ora utilizzando un webkit recente JDK-8156698 ma potrebbe avere stato un bug prima di (si può dare un'occhiata alla lista 8u112 bug fixes.

+0

Ci provo e ti faccio sapere. Grazie. :-) –

0

ho avuto lo stesso problema rendendo l'applicazione web based utilizzando angolare webview.and risolto aggiornando la versione di Java per 1.8.0_121.