JDK-8213733 : JavaFX WebView don't manage touch scroll if inserted in JFXPanel
  • Type: Bug
  • Component: javafx
  • Sub-Component: swing
  • Affected Version: 8,9,10,openjfx11
  • Priority: P3
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: generic
  • CPU: x86_64
  • Submitted: 2018-11-08
  • Updated: 2019-06-19
  • Resolved: 2019-06-19
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
openjfx13Resolved
Description
ADDITIONAL SYSTEM INFORMATION :
Windows 10 64 bit + jre/jdk 1.8.0.192

A DESCRIPTION OF THE PROBLEM :
If WebView is placed on JFXPanel its WebPage does'nt manage correctly scroll dona by mouse dragge or by touch screen. If WebView is instead attached directly to an application scroll is correctly manage even though done by touch or mouse dragged.
To replicate the issue please I run code coming from Oracle javafx tutorial pages , find below links for working and not working application:
Swing application where touch scroll  doesn't work: https://docs.oracle.com/javafx/2/swing/SimpleSwingBrowser.java.htm
JavaFX application where touch scroll works:
https://docs.oracle.com/javafx/2/webview/WebViewSample.java.htm



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Just run the attached code code or create a swing application that keep a jfxpanel with webView inside


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expect that, using atouch screen, web page could be scrolled moving fingers through the screen
ACTUAL -
web page content is selected and view doesn't scroll

---------- BEGIN SOURCE ----------

import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.embed.swing.JFXPanel;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebEvent;
import javafx.scene.web.WebView;
 
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.MalformedURLException;
import java.net.URL;
 
import static javafx.concurrent.Worker.State.FAILED;
  
public class SimpleSwingBrowser extends JFrame {
 
    private final JFXPanel jfxPanel = new JFXPanel();
    private WebEngine engine;
 
    private final JPanel panel = new JPanel(new BorderLayout());
    private final JLabel lblStatus = new JLabel();


    private final JButton btnGo = new JButton("Go");
    private final JTextField txtURL = new JTextField();
    private final JProgressBar progressBar = new JProgressBar();
 
    public SimpleSwingBrowser() {
        super();
        initComponents();
    }

    
    private void initComponents() {
        createScene();
 
        ActionListener al = new ActionListener() {
            @Override 
            public void actionPerformed(ActionEvent e) {
                loadURL(txtURL.getText());
            }
        };
 
        btnGo.addActionListener(al);
        txtURL.addActionListener(al);
  
        progressBar.setPreferredSize(new Dimension(150, 18));
        progressBar.setStringPainted(true);
  
        JPanel topBar = new JPanel(new BorderLayout(5, 0));
        topBar.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5));
        topBar.add(txtURL, BorderLayout.CENTER);
        topBar.add(btnGo, BorderLayout.EAST);
 
        JPanel statusBar = new JPanel(new BorderLayout(5, 0));
        statusBar.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5));
        statusBar.add(lblStatus, BorderLayout.CENTER);
        statusBar.add(progressBar, BorderLayout.EAST);
 
        panel.add(topBar, BorderLayout.NORTH);
        panel.add(jfxPanel, BorderLayout.CENTER);
        panel.add(statusBar, BorderLayout.SOUTH);
        
        getContentPane().add(panel);
        
        setPreferredSize(new Dimension(1024, 600));
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        pack();

    }
 
    private void createScene() {
 
        Platform.runLater(new Runnable() {
            @Override 
            public void run() {
 
                WebView view = new WebView();
                engine = view.getEngine();
 
                engine.titleProperty().addListener(new ChangeListener<String>() {
                    @Override
                    public void changed(ObservableValue<? extends String> observable, String oldValue, final String newValue) {
                        SwingUtilities.invokeLater(new Runnable() {
                            @Override 
                            public void run() {
                                SimpleSwingBrowser.this.setTitle(newValue);
                            }
                        });
                    }
                });
 
                engine.setOnStatusChanged(new EventHandler<WebEvent<String>>() {
                    @Override 
                    public void handle(final WebEvent<String> event) {
                        SwingUtilities.invokeLater(new Runnable() {
                            @Override 
                            public void run() {
                                lblStatus.setText(event.getData());
                            }
                        });
                    }
                });
 
                engine.locationProperty().addListener(new ChangeListener<String>() {
                    @Override
                    public void changed(ObservableValue<? extends String> ov, String oldValue, final String newValue) {
                        SwingUtilities.invokeLater(new Runnable() {
                            @Override 
                            public void run() {
                                txtURL.setText(newValue);
                            }
                        });
                    }
                });
 
                engine.getLoadWorker().workDoneProperty().addListener(new ChangeListener<Number>() {
                    @Override
                    public void changed(ObservableValue<? extends Number> observableValue, Number oldValue, final Number newValue) {
                        SwingUtilities.invokeLater(new Runnable() {
                            @Override 
                            public void run() {
                                progressBar.setValue(newValue.intValue());
                            }
                        });
                    }
                });

                engine.getLoadWorker()
                        .exceptionProperty()
                        .addListener(new ChangeListener<Throwable>() {
 
                            public void changed(ObservableValue<? extends Throwable> o, Throwable old, final Throwable value) {
                                if (engine.getLoadWorker().getState() == FAILED) {
                                    SwingUtilities.invokeLater(new Runnable() {
                                        @Override public void run() {
                                            JOptionPane.showMessageDialog(
                                                    panel,
                                                    (value != null) ?
                                                    engine.getLocation() + "\n" + value.getMessage() :
                                                    engine.getLocation() + "\nUnexpected error.",
                                                    "Loading error...",
                                                    JOptionPane.ERROR_MESSAGE);
                                        }
                                    });
                                }
                            }
                        });

                jfxPanel.setScene(new Scene(view));
            }
        });
    }
 
    public void loadURL(final String url) {
        Platform.runLater(new Runnable() {
            @Override 
            public void run() {
                String tmp = toURL(url);
 
                if (tmp == null) {
                    tmp = toURL("http://" + url);
                }
 
                engine.load(tmp);
            }
        });
    }

    private static String toURL(String str) {
        try {
            return new URL(str).toExternalForm();
        } catch (MalformedURLException exception) {
                return null;
        }
    }

   

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                SimpleSwingBrowser browser = new SimpleSwingBrowser();
                browser.setVisible(true);
                browser.loadURL("http://oracle.com");
           }     
       });
    }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
not found yet

FREQUENCY : always



Comments
I tried with jdk13-b21 agai nwith latest fx source built and I saw the above observation which is when I touch the vertical scrollbar and slides down on windows10 the webpage gets scrolled down and if I do not touch the vertical scrollbar and slides down, the page does not scroll down immediately but scrolls down if I slide my finger outside the FX scene.
19-06-2019

My observation is when I touch the vertical scrollbar and slides down on windows10 (with jdk12-b28), the webpage gets scrolled down. I tried with both with and without -Dcom.sun.javafx.touch=true. If I do not touch the vertical scrollbar and slides down, the page does not scroll down immediately but scrolls down if I slide my finger outside the FX scene. I assume that is expected as when I slide my finger outside the FX scene, it means the viewport is supposed to change and so scroll occurs. So, I guess this is "not reproducible" for me.
24-01-2019

Would be good to get this fixed in JavaFX 12.
15-11-2018

This is either a bug with JFXPanel (likely) or a bug in WebView (less likely).
12-11-2018

When JavaFX webview is embedded into Swing application using JFXPanel, webview page does not get scrolled using touch, unlike in webview of JavaFX application. Issue is reproducible in all JDK - 8b132, 8u192, 10.0.2, Open JavaFX 11.0.1 runtime.
12-11-2018