原諒我這個初學者問題。我試圖在HTML頁面上實現d3,該頁面顯示在Swing項目的JScrollPane中。我遵循教程@http://alignedleft.com/tutorials/d3/adding-elements。如何確定我是否已經正確實施了d3?
當我輸入代碼時,我沒有在每個點後看到模板提議。現在不想在臨時服務器上運行它。沒有出現我在運行應用程序時生成的新段落。
這是否意味着我的源鏈接到D3是錯誤地執行&因此沒有模板建議?有什麼方法可以確定DOM中的元素是否被正確選擇?但是,未嵌入腳本中的元素正確顯示。請指教。
代碼:
<!DOCTYPE html>
<html lang = "en">
<head>
<meta charset="utf-8">
<title>D3 test</title>
<script type = "text/javascript" src="d3/d3.v3.js"></script>
</head>
<body>
<script type = "text/javascript" src="d3.js">
d3.select("body").append("p").text("New paragraph!!!");
</script>
</body>
</html>
其他類:
jfxpanel = new JFXPanel();
Platform.runLater(new Runnable() {
@Override
public void run() {
try {
WebView browser = new WebView();
WebEngine engine = browser.getEngine();
//String url = "http://www.hotmail.com";
File f = new File ("src/d3/index.html"); //display local html, instead of external webpage
System.out.println("current directory: " + f.getAbsolutePath());
String url = f.toURI().toURL().toString();
engine.load(url);
Scene scene = new Scene(browser);
jfxpanel.setScene(scene);
}
catch (Exception e){
while (e != null) {
e.printStackTrace();
}
}
}
});
spVisual = new JScrollPane(jfxpanel);
//spVisual.setEnabled(false);
spVisual.setViewportBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
spVisual.setSize(800, 420);
spVisual.setLocation(100, 140);
spVisual.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
//spVisual.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
spVisual.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
spVisual.getViewport().setViewPosition(new java.awt.Point(0, 0));
}
});
add (spVisual);
通過Swing和'JScrollPane'其實際繪製組件你指的是,'JEditorPane'?請注意,沒有Swing'HTML aware'組件會對JS起作用。 – 2015-02-11 22:54:09
謝謝。我的意思是我把一個jfxpanel放到一個jscrollpane中,並希望在其中顯示一個瀏覽器。當我將jfxpanel引用到index.html時,這是成功的。那時我無法應用d3來顯示Swing應用程序中的元素。 – 2015-02-12 04:34:02
對不起,我可以知道什麼是「HTML意識」組件?這是否意味着d3不能在JFXPanel上工作? – 2015-02-12 04:44:38