【发布时间】:2015-04-10 21:20:50
【问题描述】:
我知道 JEditorPane 不能很好地呈现 Web 元素。因此我尝试了 HtmlUnit。但是,我希望将支持 JS 的浏览器嵌入到 JEditorPane 中以查看结果,并且 JEditorPane 的 .setPage() 不接受 HTML 页面而是 URL。我在一个 Javax 应用程序上。我该如何解决这个问题?
顺便说一句,稍后我需要通过 D3 将可视数据嵌入到浏览器中。感谢您提供的所有建议。
这是我的代码 sn-p:
webclient = new WebClient (BrowserVersion.CHROME);
currentpage = (HtmlPage) webclient.getPage("http://www.stackoverflow.com");
currentpage.executeJavaScript("document.write('Hello World!');");
jepuser = new JEditorPane();
jepuser.setEditable(false);
try{
jepuser.setPage(currentpage); //<---
jepuser.setContentType("text/html");
jepuser.updateUI();
}
catch(IOException e){
System.err.println(e);
}
spuser = new JScrollPane(jepuser);
spuser.setViewportBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
spuser.setSize(800, 420);
spuser.setLocation(280, 140);
spuser.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
//spuser.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
spuser.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
add(spuser, BorderLayout.CENTER);
【问题讨论】:
标签: java htmlunit jeditorpane