0

I'm making a swing application with Url load in JavaFX browser inside frame. I have to divide that browser frame in to two parts as in left side of frame content will be show and in right side image will be show.

import java.awt.BorderLayout; 
import javafx.application.Application; 
import javafx.beans.value.ChangeListener; 
import javafx.beans.value.ObservableValue; 
import javafx.collections.ObservableList;
import javafx.concurrent.Worker; 
import javafx.concurrent.Worker.State; 
import javafx.embed.swing.JFXPanel; 
import javafx.scene.Group;
import javafx.scene.Node; 
import javafx.scene.Scene; 
import javafx.scene.control.ScrollPane; 
import javafx.scene.web.WebEngine; 
import javafx.scene.web.WebView; 
import javafx.stage.Stage; 

public class Main extends Application { 
   @Override 
 public void start(final Stage stage) { 
stage.setWidth(400); 
stage.setHeight(500); 

 Scene scene = new Scene(new Group()); 
//Group root = new Group();  
   // Scene scene = new Scene(root,80,20); 

final WebView browser = new WebView(); 
final WebEngine webEngine = browser.getEngine(); 

ScrollPane scrollPane = new ScrollPane(); 
scrollPane.setContent(browser); 

webEngine.getLoadWorker().stateProperty() 
    .addListener(new ChangeListener<State>() { 
      @Override 
      public void changed(ObservableValue ov, State oldState, State newState) { 

        if (newState == Worker.State.SUCCEEDED) { 
          stage.setTitle(webEngine.getLocation()); 
    stage.setTitle(webEngine.getLocation()); 
          String trgurl=webEngine.getLocation(); 
          System.out.println(trgurl); 
              if(trgurl.matches("(.*)img=(.*)")){ 

                 int n = trgurl.indexOf("&img="); 
                  System.out.println(n+7); 
                  int len = trgurl.length(); 
                  System.out.println("string length is: 
"+trgurl.length()); 
                  System.out.println(trgurl.substring(n+7,len)); 
                  String find = "file://"+trgurl.substring(n+7,len); 
                  System.out.println(find); 
              try { 
                  new File(find).toURI().toURL(); 
              } 
              catch(Exception e){ 

              } 
              } 
        } 

        } 


    }); 
webEngine.load("http://www.example.com");

scene.setRoot(scrollPane); 

stage.setScene(scene); 
stage.show(); 
stage.setResizable(true);  


 } 


 private static void extracted(String[] args) { 

 launch(args); 

 } 
}  

When I load this url in left side of scrollpane content is loading but in right side no image is loading other than that there is no error in this program. And if i try to add browser to internal frame how is it possible

1 Answers1

0

Like this u can divide the single url into two browser ie images loade at one browser and content at another enter code here /*

    package jdesktop;


 import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker;
import javafx.event.ActionEvent;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

public class NewClass extends Application {

    private static Object webEngine;

    @Override
    public void start(final Stage stage) {


       final WebView browser = new WebView();
       final WebEngine webEngine = browser.getEngine();

         final WebView browser1 = new WebView();
       final WebEngine webEngine1 = browser1.getEngine();


       webEngine.getLoadWorker().stateProperty()
        .addListener(new ChangeListener<Worker.State>() {


          @Override
          public void changed(ObservableValue ov, Worker.State oldState, Worker.State newState) {
            if (newState == Worker.State.SUCCEEDED) {
              stage.setTitle(webEngine.getLocation());
              String trgurl=webEngine.getLocation();
              System.out.println(trgurl);

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

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

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


        }
            }
          }
        });

       String url = "http://192.168.2.18/a3/host/pmms.ankiti.com/?";
                // Load a page from remote url.
               webEngine.load(url);
       buttonURL.setOnAction((ActionEvent event) -> {
           String url1 = "http://192.168.2.18/a3/host/pmms.ankiti.com/?";
             // Load a page from remote url.
             webEngine.load(url1);
         });



        HBox root = new HBox();
        root.setPadding(new Insets(3));
        root.setSpacing(3);
        root.getChildren().addAll( browser1,browser);


        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.setWidth(450);
        stage.setHeight(300);

        stage.show();

          }
    public static void main(String[] args) {
        launch(args);
    try {
              String webEngineLocation = webEngine.getLocation();
                        URL url = new URL(webEngineLocation); 


        } catch (MalformedURLException e) {
        }
    }
}