Strange behavior on the web page of preloading in WebView

I have the following problem: in my Swing application, I want to display a web page. To do this, I use a JFXPanel that contains a WebView. The web page must be loaded in the background, and only if the loading process is totally finished I want to make the JFXPanel visible. I use thegetLoadWorker().workDoneProperty() method of the corresponding WebEngine to determine if the page is totally loaded.

The problem is, now that the JFXPanel gets visible, I see initially a totally empty Board, and after a short period, the web page in Web view is visible. I made a simple Application demo that reproduces this behavior. If the page is loaded, a button is enabled and clicking on this button adds the WebView Panel below. In addition the link following points to an animated gif that shows the behavior: http://tinypic.com/view.php?pic=oh66bl & s = 5 #. Ujv2IhddWKl

Here is the code of the demo application:

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class WebViewTest extends javax.swing.JPanel {

   private static JFXPanel browserFxPanel;
   private WebView webView;
   private WebEngine eng;

   /**
  * Creates new form WebViewTest
  */
   public WebViewTest() {
  initComponents();
   Platform.setImplicitExit(false);
  browserFxPanel = new JFXPanel();
   Platform.runLater(new Runnable() {
   public void run() {
  webView = createBrowser();
   Scene scene = new Scene(webView);
  scene.setFill(null);
  browserFxPanel.setScene(
  scene);
   }
   });
   }

   /**
  * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The
  * content of this method is always regenerated by the Form Editor.
  */
   @SuppressWarnings("unchecked")
   // <editor-fold defaultstate="collapsed" desc="Generated Code">  
   private void initComponents() {
  java.awt.GridBagConstraints gridBagConstraints;

  pnlMain = new javax.swing.JPanel();
  showWebpageButton = new javax.swing.JButton();

  setLayout(new java.awt.GridBagLayout());

  pnlMain.setLayout(new java.awt.BorderLayout());
  gridBagConstraints = new java.awt.GridBagConstraints();
  gridBagConstraints.gridx = 0;
  gridBagConstraints.gridy = 1;
  gridBagConstraints.gridwidth = 3;
  gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
  gridBagConstraints.weightx = 1.0;
  gridBagConstraints.weighty = 1.0;
  add(pnlMain, gridBagConstraints);

  showWebpageButton.setText("show web page");
  showWebpageButton.setEnabled(false);
  showWebpageButton.addActionListener(new java.awt.event.ActionListener() {
   public void actionPerformed(java.awt.event.ActionEvent evt) {
  showWebpageButtonActionPerformed(evt);
   }
   });
  gridBagConstraints = new java.awt.GridBagConstraints();
  gridBagConstraints.gridx = 1;
  gridBagConstraints.gridy = 0;
  gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
  add(showWebpageButton, gridBagConstraints);
   }// </editor-fold>  

   private void showWebpageButtonActionPerformed(java.awt.event.ActionEvent evt) {   
  pnlMain.removeAll();
  pnlMain.add(browserFxPanel, BorderLayout.CENTER);
   WebViewTest.this.invalidate();
   WebViewTest.this.revalidate();
   }   
   // Variables declaration - do not modify  
   private javax.swing.JPanel pnlMain;
   private javax.swing.JButton showWebpageButton;
   // End of variables declaration  

   private WebView createBrowser() {
   Double widthDouble = pnlMain.getSize().getWidth();
   Double heightDouble = pnlMain.getSize().getHeight();
   final WebView view = new WebView();
  view.setMinSize(widthDouble, heightDouble);
  view.setPrefSize(widthDouble, heightDouble);
  eng = view.getEngine();
  eng.load("http://todomvc.com/architecture-examples/angularjs/#/");
  eng.getLoadWorker().workDoneProperty().addListener(new ChangeListener<Number>() {
   public void changed(ObservableValue<? extends Number> ov, Number t, Number t1) {
   final double workDone = eng.getLoadWorker().getWorkDone();
   final double totalWork = eng.getLoadWorker().getTotalWork();
   if (workDone == totalWork) {
  showWebpageButton.setEnabled(true);
   }
   }
   });
   return view;
   }

   public static void main(String[] args) {
   SwingUtilities.invokeLater(new Runnable() {
   public void run() {
   final JFrame f = new JFrame("Navigator Dummy");
  f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  f.setSize(new Dimension(1024, 800));
   final WebViewTest navDummy = new WebViewTest();
  f.getContentPane().add(navDummy);
  f.setVisible(true);
   }
   });
   }
}


I don "t understand this behavior, in fact the page has already been loaded. To me, it seems that the WebView starts to render the site just to the point where it becomes visible. What can I do to get the WebView already shows the web page is loaded right now that it becomes Visible (to avoid this effect of flickr)?

I already posted this question on StackOverflow (see http://stackoverflow.com/questions/18873315/javafx-webview-loading-page-in-background ) but didn't get an answer and found this forum today.

Thanks in advance!

Try the updated version in this post.

It requires a snapshot offscreen before displaying the Web mode to make sure all is rendered before the Web is displayed.

The code is kind of ugly and the 'solution' is a bit of a hack, you would probably want to clean it up a bit before using it anywhere (for example, there is no need to create a new WebView and snapshot, web page on each load - I did it just to get a feel for the worst-case scenario and try to pinpoint where are produce slowdowns).

A small rectangle moves back on the top of the screen so that the fluidity of the animation can be monitored.

On the first charge, there will be a slight stutter in the animation, but the rendered web page instantly appears when click the show page"" button.

As you say, the stuttering occurs only the first time the page is loaded, then everything is smooth.  If you use a progress bar regular instead of an animation, the initial stuttering is probably fine, because people expect to see breaks in the progress bars from time to time (more progress reported by progress bars is not a smooth linear progression).  My guess is that if you use a regular progress bar, the behavior seen with this example is probably acceptable for almost all users.

As for the differences between the rendering between 2.2 JavaFX and JavaFX 8, there was a lot of changes to the internal architecture of JavaFX for JavaFX 8 that have improved rendering performance, as well as probably represents the delta.

import javafx.animation.*;
import javafx.application.Application;
import javafx.concurrent.Worker;
import javafx.geometry.*;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import javafx.util.Duration;

public class WebViewJavaFXTest extends Application {
    public static final String PAGE_URL = "http://todomvc.com/architecture-examples/angularjs/#/";
    private Rectangle distractor;

    @Override
    public void start(Stage stage) throws Exception {
        distractor = new Rectangle(20, 20, Color.CORAL);
        TranslateTransition r = new TranslateTransition(Duration.seconds(10), distractor);
        r.setFromX(0);
        r.setToX(800);
        r.setInterpolator(Interpolator.LINEAR);
        r.setCycleCount(RotateTransition.INDEFINITE);
        r.setAutoReverse(true);
        r.play();

        VBox layout = initView();
        stage.setScene(new Scene(layout));
        stage.show();
    }

    private VBox initView() {
        final ProgressBar progress = new ProgressBar();
        final Button showWebView = new Button("Show Page");
        showWebView.setDisable(true);
        HBox controls = new HBox(
                10,
                progress,
                showWebView
        );
        controls.setAlignment(Pos.CENTER_LEFT);
        Button tryAgain = new Button("Try Again");
        tryAgain.setOnAction(actionEvent ->
                tryAgain.getScene().setRoot(
                        initView()
                )
        );

        StackPane webViewHolder = new StackPane();
        webViewHolder.setPrefSize(1024, 700);

        final WebView webView = new WebView();
        progress.progressProperty().bind(
                webView.getEngine().getLoadWorker().progressProperty()
        );
        webView.setPrefSize(1024, 700);
        webView.getEngine().load(PAGE_URL);
        webView.getEngine().getLoadWorker().stateProperty().addListener(
                (o, old, state) -> {
                    if (state == Worker.State.SUCCEEDED) {
                        webView.snapshot(
                                snapshotResult -> {
                                    showWebView.setDisable(false);
                                    return null;
                                },
                                null,
                                null
                        );
                    } else {
                        showWebView.setDisable(true);
                    }
                }
        );

        showWebView.setOnAction(actionEvent -> {
            controls.getChildren().setAll(
                    tryAgain
            );
            webViewHolder.getChildren().setAll(webView);
        });
        VBox layout = new VBox(
                10,
                distractor,
                controls,
                webViewHolder
        );
        layout.setPadding(new Insets(10));

        return layout;
    }

    public static void main(String[] args) {
        launch();
    }

}

Tags: Java

Similar Questions

  • When visit web page strange symbols cover the web page, it happens on sites visited, confirmed that the site and page visited is normal on the other pc.

    I scanned for malware using Spy Bot, EAST Smart Security, Microsoft security essentials and IO bit Malware Fighter. All of them are own return. Have uninstalled Firefox and clean Firefox installed after the reboot.
    Still no change. I thank in advance for any suggestions on how to fix. Note it is sent from the 2nd PC that does not have the problem described.

    Hello, try to start the computer in safe mode Windows with network support (on the startup screen, press F8) and check again.

    (If running Windows in safe mode, then you have a problem with other software, such as security software [antivirus, firewall] or a system driver that runs on your computer).

    Thank you

  • The Web pages in IE8 see the lowercase and do not whole screen

    I pushed a few keys on my keyboard and now what has happened (with only the web page - toolbars and these are full-screen) and I want my old pictures back screen.  How can I adkust the size of the screen so that it fills the entire screen again?  I wish that I knewt what I did to cause this because that's probably how to cancel - and I can't display in the Panel as in XP.  I tried zoom and do it to fill the entire page, but the font size is too much - I want fonts smaller than I had before.

    Thanks in advance for your help. Lorien - a - MCSE/MCSA/network + / A +.

    What worked for me was to adjust IE from within IE using the drop-down menu of the Page then Zoom and the size of the text until I had him where I wanted.  Then I closed it and all of the following openings open like this was closed (which is now the default behavior).

    I hope it works for you.

    Good luck! Lorien - a - MCSE/MCSA/network + / A +.

  • Strange behavior with the PSD in Photoshop

    I am currently working with a two-page ID CS5.5 document. This is a CMYK document with CMYK images and grayscale.

    Strange behavior is the following: I have a gray levels (tiff) image that is repeated on the page 1 and page 2. This image looks completely different from page 1 to page 2. I have triple checked everything (opactiy, effects, etc.) and then I started to remove items from page 2 one by one.

    As I deleted a psd file all of a sudden all the images in grayscale on page 2 changed his appearance to match page 1. The PSD in question is also in CMYK with a transparent background. What the frack happens?

    I'm more concerned to know if it makes a difference when it goes to print, or if it's just weird screen in InDesign.

    Anyone who has heard of this or know why this happens - would like to hear from you.

    Thank you!

    I think it's simply because of full transparency on the page. Should not affect the production of gray images... but check in Acrobat.

    Mike

  • How to prevent large gaps on the Web page when you use the behaviours slide?

    I searched the forums for similar problems with application behavior slide to the elements through the DW CS5 interface and find a useful post titled "problem with Spry Applying"Slide Effect"so now my slide effects works the way I want to, except instead of dragging out a legend after clicking on an image I slip on a list of text items when you click on a section of text.  It works, but there is a gap when the first load of the Web page. How can I remove/avoid this great whitespace to appear?

    < ! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional / / IN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > ""

    " < html xmlns =" http://www.w3.org/1999/xhtml ">

    < head >

    < meta http-equiv = "Content-Type" content = text/html"; Charset = UTF-8 "/ >"

    < title > test Document < /title >

    "<!-< script type =" text/javascript"src ="... / SpryAssets/SpryEffects.js "> < / script > - >"

    < script src = "SpryAssets/SpryEffects.js" type = "text/javascript" > < / script > "

    < script type = "text/javascript" >

    function MM_effectSlide (targetElement, duration, of, to, toggle)

    {

    Spry.Effect.DoSlide (targetElement, {duration: duration,:, to: to, turn on/off: toggle});

    }

    < /script >

    < / head >

    < body >

    < p > < / p >

    < p > < / p >

    < style type = "text/css" >

    #LOdiv {visibility: hidden ;}}

    #Countries {visibility: hidden ;}}

    < / style >

    < p > < / p >

    < p > < / p >

    (< div id = "Latte" onclick = "MM_effectSlide ('LOdiv', 1000,"0% ", 100%", true) ">"

    < p > < strong > drop-down list One + show < facilities > < / p >

    < / div >

    < div id = "LOdiv" >

    < div >

    -Item A < br / >

    -Point B < br / >

    -Point C < br / >

    -Section D < br / >

    -Point E < br / >

    -Item F < br / >

    -G spot < br / >

    -Point H < br / >

    -I point < / div >

    < / div >

    < / div >

    (< div id = "ListTwo" onclick = "MM_effectSlide ('country', 1000,"0% ", 100%", true) ">"

    < p > < strong > list two + show < facilities > < / p >

    < / div >

    < div id = 'Country' >

    < div >

    -USA < br / >

    -Germany < br / >

    -France < br / >

    -Italy < br / >

    -Japan < br / >

    -China < br / >

    < / div >

    < / div >

    < span style = "width: 990px;" height: 21px' > < img width = 990 height = 21

    SRC = "image386.gif" >

    </span >

    < / body >

    < / html >

    Hello

    in my opinion, this technique is not designed for the two panels. To do this you must use the "Spry several sliding elements"-technique in which panels will be triggered by the individual buttons. "" Here is the link for it:

    http://labs.adobe.com/technologies/spry/samples/effects/multiple_slides_sample.html.

    Hans-Günter

  • Firefox does not open in full screen on the task bar and I have to go over it to see the web page.

    Firefox does not open in full screen on the task bar and I have to go over it to see the web page.

    Firefox window is sometimes "off screen" somehow. Often, you can force it to appear on the screen by right clicking on the thumbnail image just above the taskbar and choose expand. Does it work?

    A possible cause for this is that the file that stores the positions and sizes of window is corrupt. You can delete this file and Firefox will return to standard window resizing.

    #1 method: If you can get a zoomed window:

    Open the settings folder (AKA Firefox profile) current Firefox help

    • button "3-bar" menu > "?" button > troubleshooting information
    • (menu bar) Help > troubleshooting information
    • type or paste everything: in the address bar and press Enter

    In the first table of the page, click on the view file"" button. This should launch a new window that lists the various files and folders in Windows Explorer.

    Leave this window open, switch back to Firefox and output, either:

    • "3-bar" menu button > button "power".
    • (menu bar) File > Exit

    Pause while Firefox finishing its cleanup, then rename xulstore.json to something like xulstore.old. If you see a file named localstore.rdf, rename this to localstore.old.

    Launch Firefox back up again. Windows normally appear again?

    #2 method: If you can not get a Firefox window for all:

    Close Firefox by right clicking the icon in the taskbar > close all windows.

    Using the Run dialog box (windows key + R) or the start search bar menu type or paste the following and press Enter to drill down to the profiles folder:

    %APPDATA%\Mozilla\Firefox\Profiles
    

    Here you can see a folder - in this case, double-click that - or more than one case - in this case, double-click on in what looks like the most recently updated.

    Scroll down and rename xulstore.json to something like xulstore.old. If you see a file named localstore.rdf, rename this to localstore.old.

    Launch Firefox back up again. Windows normally appear again?

    Then, to re - light bars, you can use one of the following methods to view the list of the toolbar, and then select the desired bars it:

    To activate the menu bar, toolbar bookmarks or other bars, click it in the list.

  • Is there a option of zoon of the Web pages with Mozilla Firefox, if I have trouble reading the small print?

    I take a class any web business, and I can't find a lot of the functions that they speak.

    Hello
    Have you tried the Firefox zoom feature? This initiative will increase the size of the web pages.

    • To make things bigger, press Ctrl and + at the same time.
    • To make things smaller, press Ctrl and - at the same time.
    • Pour reinitialiser to reset the size of return to normal, press Ctrl and 0 at the same time.

    You can also use the NoSquint add-on to change the zoom level by default for all websites at the same time. After setting your overall zoom level, you can still adjust the zoom on different sites.

    With the help of NoSquint:

    1. After installation of NoSquint, make sure you have the add-on bar displayed:

      • Click the new tab button ("+") or a box empty bar tab to the right of the item and choose the module bar on the shortcut menu.
    2. Click on the % in the bar of the add-on call site preferences, then click the global settings button, then the zoom tab.
      • You can experiment with sizes greater than 125%, but it is not recommended that you will more than 150%, unless you have a large screen high resolution.

    If there are sites that are still a concern, feel free to post their URLs.

    Please let us know if this helped you!

    Thank you.

  • Back to the same place of the web page

    When I click on the arrow to the left happens to me on web page, I was ahead, but there also go to the top of the page, but not to the task, I was working, so I have to scroll down to this place. How can I get back to this place on the web page?

    Three ways:
    1. click the link
    2 {Ctrl + click} link
    3. right click on the link and use open link in a new tab

  • Does not load the Web page.

    It will not load the web page. It gives an error message or to say that it has expired. The circle on the tab will turn to a stop bit while then just, and nothing comes up. I uninstalled, and re-installed and still gives me this problem. I checked the updates and I am running the latest version.

    I disabled my firewall on my Norton Internet Security and Firefox work again. I activated the firewall back and it still works, go figure.

  • Save the web page

    Using Safari, if you are on a Web page and click file > save as, you will be able to save the contents of this Web page on your local computer, even if the content leaves the original source of the web in the future?

    Thank you

    It should stay even if the web page changes.

  • TB refuses my password - pswd is good because I can access e-mail on the web page of Yahoo from Verizon

    I use Yahoo from Verizon. Everything has worked when suddenly Thunderbird does not accept my password to give me the following error message: "sending the password failed. "Mail server incoming.yahoo.verizon.net replied: (#AUTH012) Incorrect username or password".

    However, the password is good because I can log on and get my email from the web page of Yahoo from Verizon.

    The problem is solved. Verizon-Yahoo never was informed to change the user ID in the settings of my account xxxxxx in [email protected], that is, simply add the @verizon.net to your user name on the server settings page.

  • I can't open the web pages included in emails.

    The e-mails often contain links to a Web page. When I click on these links, nothing happens. The Web page will not open.

    jmildred

    https://support.Mozilla.org/en-us/KB/hyperlinks-in-messages-not-working

  • It has been updated and I don't see the web page. It is only a blank page. Android for Tablet

    I could see a Web page that starts with https. However, the browser has been updated and 1 can no longer see the web page. I can see it in chrome, but I need Firefox because of the plug ins.

    Default browser got back to Chrome as liberation V30.0 seems to have a lot of problems loading pages to open links from other applications. The same url will load fine in Chrome.

  • I get a strange behavior of the bar tabs and the address bar in Firefox 29,0 for Mac.

    I just installed Firefox 29,0 for Mac.
    I have a strange behavior of the bar tabs and the address bar with this new version.
    Instead of the address bar, I get two rows of symbols. And it is impossible to write anything in the address bar.
    (I add a screenshot, but I can't find a way to do it).

    Firefox has an RSS icon in the palette of the toolbar that you can drag a toolbar (but not on the location bar container).

    • Firefox menu button > Options/Preferences > toolbars
    • View > toolbars > customize
  • Message from the Web page: "Scanstyles does nothing in Webkit/Firefox". I get this popup when I'm in my site of the Financial Institution.

    This popup occurs whenever I select an account in the Web page to view its details. Once I click OK it disappears, but appears again when when I select another account for display. It is not a barrier to the operation but rather boring.

    I guess that site does not support the basis of Webkit and Gecko according to browsers.

    WebKit - Chrome, Safari, etc of Midori.
    Gecko - Pale Moon, Firefox etc.

    Have you tried on IE (Trident based).

Maybe you are looking for

  • Unable to add search engines?

    My search bar has never worked. Not when I had 3 of Firefox... and no, not now. I had to add a toolbar, in order to be able to search. It's been very wide Firefox and ugly looking. I didn't like it and so I don't want to add again, now that I've got

  • Need for biometrics and masstorage drivers for Satellite A105-SP4088

    Hello. I have need the drivers of biometrics and masstorage.Can someone tell where I can download this driver?I am looking at page all media from Toshiba. Recently I formatted my laptop. I do not have CD with drivers. I thank you,Raul Yahtnel

  • Satellite Pro C660-1nq - cant access HDD recovery

    Hello Sorry to bother you but I need help if possible.I'm trying to restore my laptop to factory settings and I am pressing f8.However, I get all the system recovery options, but no Toshiba hard drive recovery option. What I am doing wrong?

  • My IPhone6 says to connect to iTunes but it doesn't recognize my mac, what do I do?

    IPhone 6 by updating the software just stops without finishing and tells me to connect it to iTunes. The thing is that my mac does not recognize it (it recognizes other iPhones) iPhone ^ iOS 9.2, MacBook Air I'OS X El Capitan 10.11.3

  • Docking station ruin the battery?

    HelloMy old laptop was a something Lenovo that has been duplicated for me 1 and the same version for my parents...I use to keep my AC when 100% or my battery out when I'm at home. |While they were trendy - overload 24/7...After 2 years mine was still