2

Does anybody have an idea how to make the WebView pannable in JavaFX? I know, that WebView is a child of the ScrollPane in JavaFX, and it is possible to make a ScrollPane pannable easily. But I have no idea how to make it pannable with a simple WebView.

If you have any ideas, please let me know. Maybe with Javascript, but how? Thanks in advance!

SGE59
  • 37
  • 5

1 Answers1

1

Making a site srollable by mouse dragging is a html thing so first remove the scrollbar from the <body> by adding following css to the site:

body {
    overflow-x: hidden;
    overflow-y: hidden;
}

(if you don't know how to add css to a webview see this)

Then to enable the scrolling by dragging it you must use javascript. (see this question but it uses jquery).

OR

you can use this library (link) i found.

then add this to the html:

<script type="text/javascript" src="https://cdn.rawgit.com/asvd/dragscroll/master/dragscroll.js" />

and

also add a class named dragscroll to whatever you want to make scrollable by drag (in your case <body>).

(if you have trouble with adding elements or attributes i can recommend you JSoup as html parser)

fuggerjaki61
  • 822
  • 1
  • 11
  • 24
  • webview.setHbarPolicy(ScrollBarPolicy.NEVER); webview.setVbarPolicy(ScrollBarPolicy.NEVER); is not possible with WebView. Just give the WebView a class in CSS and remove the ScrollBars. But with you're solutions mentioned in the answer it works fine ! :) – SGE59 Jan 10 '20 at 10:56
  • @SGE59 i thought it had these policies(it was described like this in another older question). I will edit the question :) – fuggerjaki61 Jan 10 '20 at 14:45