[for reference i had attached my application screenshot if u see the page which is open up is also same and down one also same thats why i have to stop navigation of above webview so it can open in down one only ][1]

 public class HV extends Application
    {
        @Override
        public void start(Stage primaryStage) throws Exception
        {                   
            StackPane root = new StackPane();

        HBox hbox = new HBox(30); // create a HBox to hold 2 vboxes        

        // create a vbox with a textarea that grows vertically
        VBox vbox = new VBox(10);  
        final WebView img = new WebView();
          final WebEngine webEngineImg = img.getEngine();     
        vbox.getChildren().addAll(img);

        // create a vbox that grows horizontally inside the hbox
        VBox vbox2 = new VBox();        
        final WebView browser = new WebView();
       final WebEngine webEngine = browser.getEngine();

         final WebView browser1 = new WebView();
       final WebEngine webEngine1 = browser1.getEngine();
          webEngine1.getLoadWorker().stateProperty()
        .addListener(new ChangeListener<Worker.State>() {
          @Override
          public void changed(ObservableValue ov, Worker.State oldState, Worker.State newState) {
            if (newState == Worker.State.SUCCEEDED) {
             primaryStage.setTitle(webEngine1.getLocation());
              String trgurl=webEngine1.getLocation();
              System.out.println(trgurl);


              if(trgurl.matches("(.*)img=(.*)")){

                  int n = trgurl.indexOf("img=");
                  //String str1 = Integer.toString(n);
                  System.out.println(n+4);
                  int len = trgurl.length();
                  System.out.println("string length is: "+trgurl.length());
                  System.out.println(trgurl.substring(n+4,len));
                  String find = "file:"+trgurl.substring(n+4,len);
                  System.out.println(find);

                  webEngineImg.load(find);
                  //webEngine1.load(find);// this is loading image

                  if (trgurl.matches("(.*)target=wb2(.*)")){
                      //int n1= trgurl.indexOf("target=");
                      //String str1 = Integer.toString(n);
                    //  System.out.println(n1+7);
                    //  System.out.println(trgurl.substring(n1+7,98));
                      boolean cancel();
                     webEngine.load("url");

                       }  
              }
             }
          }

        });

        webEngine1.load("url");
       // String url = "https://eclipse.org";
                // Load a page from remote url.
              //  webEngine.load(url);

        vbox2.setPadding(new Insets(3));
        vbox2.setSpacing(3);
         vbox2.getChildren().addAll( browser1,browser);

        HBox.setHgrow(vbox2, Priority.ALWAYS);


        hbox.setPadding(new Insets(20));
//        StackPane.setMargin(hbox, new Insets(20));

        hbox.getChildren().addAll(vbox, vbox2);
        root.getChildren().add(hbox);
        Scene scene = new Scene(root, 500, 300); // the stack pane is the root node


        primaryStage.setScene(scene);
        primaryStage.show();        
    }

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

    }
} 

for debbuging - this is my code which have three webview in webview1 complete site open and in webviewimg only images from the action of webview1 open and in webview i want to load a edit url but for that i have to disable a navigation of that link in webview1 so that i can open that in webview so i had try platform.runlater to run that link after in other webview but im getting error that state cannot be change in to string this is a piece of code where im trying to add

webEngine1.getLoadWorker().stateProperty()
       .addListener(new ChangeListener<Worker.State>() {
          @Override
          public void changed(ObservableValue ov, Worker.State oldState, Worker.State newState) {
            if (newState == Worker.State.SUCCEEDED) {
             primaryStage.setTitle(webEngine1.getLocation());
              String trgurl=webEngine1.getLocation();
              System.out.println(trgurl);
            if ((address.getQuery() + "").contains("target=true"))
            {
                Platform.runLater(() -> {
                    grid_layout.getChildren().remove(webEngine1);
                    grid_layout.add(webEngine1, 0, 1);
                    webEngine1.load(oldState);

or how to insert jquery in java to prevent navigation code is here

document.addEventListener('click', function(e) {
    e.stopPropagation();
 }, true);
1

There are 1 best solutions below

0
On

Problem solved. Here is the code:

public class HV extends Application
{

@Override
public void start(Stage primaryStage) throws Exception
{   

    StackPane root = new StackPane();

    HBox hbox = new HBox(30); // create a HBox to hold 2 vboxes        

    // create a vbox with a textarea that grows vertically
    VBox vbox = new VBox(10);  
    final WebView img = new WebView();
      final WebEngine Img = img.getEngine();     
    vbox.getChildren().addAll(img);

    // create a vbox that grows horizontally inside the hbox
    VBox vbox2 = new VBox();        
    final WebView browser = new WebView();
   final WebEngine wb2 = browser.getEngine();

     final WebView browser1 = new WebView();
   final WebEngine wb1 = browser1.getEngine();
      wb1.getLoadWorker().stateProperty()
   .addListener(new ChangeListener<Worker.State>() {
      @Override
      public void changed(ObservableValue ov, Worker.State oldState, Worker.State newState) {
                Platform.runLater(() -> {
                    final WebEngine wb1 = browser1.getEngine();
                    if (wb1.getLocation().contains("img")) {
                        System.out.println("BrowserPane.ChangeListener cancelling " + wb1.getLocation());
                        wb1.getLoadWorker().cancel();
                        //  if (newState == Worker.State.SCHEDULED) {
                        primaryStage.setTitle(wb1.getLocation());
                        String trgurl = wb1.getLocation();
                        System.out.println(trgurl);
                           if(trgurl.matches("(.*)img=(.*)")){
              int n = trgurl.indexOf("img=");
              //String str1 = Integer.toString(n);
              System.out.println(n+4);
              int len = trgurl.length();
              System.out.println("string length is: "+trgurl.length());
              System.out.println(trgurl.substring(n+4,len));
              String find = "file:"+trgurl.substring(n+4,len);
              System.out.println(find);

              Img.load(find);
                        //webEngine1.load(find);// this is loading image
                        if (trgurl.matches("(.*)target=wb2(.*)")){
                            int n1= trgurl.indexOf("target=wb2");
                            String str1 = Integer.toString(n1+10);
                            System.out.println(n1+10);
                            System.out.println(trgurl.substring(0,n1+10));
                            String find1= ""+trgurl.substring(0,n1+10);
                            System.out.println(find1);
                            // boolean cancel();
                            wb2.load(find1);
                        }
                        }
                        }  
                        });
                        } 
                        });






    wb1.load("url");
   // String url = "https://eclipse.org";
            // Load a page from remote url.
          //  webEngine.load(url);

    vbox2.setPadding(new Insets(3));
    vbox2.setSpacing(3);
     vbox2.getChildren().addAll( browser1,browser);

    HBox.setHgrow(vbox2, Priority.ALWAYS);


    hbox.setPadding(new Insets(20));
//        StackPane.setMargin(hbox, new Insets(20));

    hbox.getChildren().addAll(vbox, vbox2);
    root.getChildren().add(hbox);
    Scene scene = new Scene(root, 500, 300); // the stack pane is the root node


    primaryStage.setScene(scene);
    primaryStage.show();
 }  

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

}
}

By using platform.runlater() and after the listener cancel the loadworker by getloadworker.cancel()