如何在浏览器中将框架分为两部分?

时间:2017-08-17 05:08:34

标签: java swing javafx jscrollpane jsplitpane

我正在框架内的JavaFX浏览器中使用Url加载制作swing应用程序。我必须将浏览器框架分成两部分,因为框架内容的左侧将显示,右侧图像将显示。

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); 

 } 
}  

当我在滚动窗格左侧加载此网址时,内容正在加载,但在右侧没有加载图像,除此之外没有错误。 如果我尝试将浏览器添加到内部框架怎么可能

1 个答案:

答案 0 :(得分:0)

像这样你可以将单个网址划分为两个浏览器,即图像在一个浏览器中呈现,而另一个内容在此输入代码/ *

    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) {
        }
    }
}