我正在尝试通过使用以下代码在另一个Web视图中打开网页。在此程序中,我在一个test1.htm中使用两个Web视图,并且我想单击第一个Web视图中的超链接,新页面应在另一个Web视图中打开
class webcontrol extends JFrame
{
webcontrol()
{
setLayout(null);
Container cp=this.getContentPane();
fxpanel= new JFXPanel();
add(fxpanel);
fxpanel.setBounds(660, 0, 230, screenSize.height-120);
Platform.runLater(new Runnable() {
public void run()
{
initFx(fxpanel,fxpanel1);
}
}
);
}
private static void initFx(final JFXPanel fxpanel, JFXPanel fxpanel1)
{
WebView webview=null,webview1=null;
WebEngine eng=null,eng1=null;
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Group group1= new Group();
Scene scene1= new Scene(group1);
fxpanel1.setScene(scene1);
webview1 = new WebView ();
group1.getChildren().removeAll();
group1.getChildren().add(webview1);
Group group= new Group();
Scene scene= new Scene(group);
fxpanel.setScene(scene);
webview = new WebView ();
group.getChildren().removeAll();
group.getChildren().add(webview);
eng= webview.getEngine();
eng1=webview1.getEngine();
File htmlFile = new File("d:/newfolder/test.htm");
File htmlFile1 = new File("d:/newfolder/test1.htm");
try
{
eng.load(htmlFile.toURI().toURL().toString());
eng1.load(htmlFile1.toURI().toURL().toString());
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
最佳答案
在以下位置没有关闭字符串:
("d:/newfolder/test1.htm);
在哪里
("d:/newfolder/test.htm");
很好