Question

I am trying to open an HTML file using JavaFX webview . If the page needed the scrollbar its automatically adding the scroll bar to the page. My query is to change the position of the scroll bar ,suppose i want that the scrolling should be from the 300 x co-ordinate of the screen size. Even on another button click i want to get the current position of the scroll bar

For opening the file I am using the following code.

call the following method on button click like following

        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
                 Platform.runLater(new Runnable() {
                    public void run()
                    {
                     initFx(xfxpanel);
                     }}
                    );
       }



  private void initFx(final JFXPanel fxpanel)
  {
  try
{ 
File f1=new File("path of the html file"); 
Group group= new Group();
Scene scene= new Scene(group);
fxpanel.setScene(scene);  
jsp=new JScrollPane(fxpanel);

add(jsp);
jsp.setBounds(0,0,1024,768);

WebEngine eng;
webview = new WebView ();
group.getChildren().add(webview);
webview.setMinSize(1024,768);
webview.setMaxSize(1024,768);  
webview.setVisible(true);
eng= webview.getEngine();

eng.setJavaScriptEnabled(true);


  eng.load(f1.toURI().toURL().toString());

  }
 catch(Exception ex)
 { 
  ex.printStackTrace();
 }
}
Was it helpful?

Solution

Use scrollPanesContent.scrollRectToVisible(new Rectangle(...));

Or you can get vertical and horizontal scrollbars and call setValue(desiredValue);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top