2013-04-05 96 views
0

我有一個FXML文件,其中有一個窗格作爲它的條目之一,用於我們程序的輸出。我想讓這個窗格包含一個HTMLEditor。我對如何做到這一點有點困惑。該類使用建議的Singleton模式,我可以調用Controller來獲取窗格。JavaFX將自定義項目添加到窗格

然後我發現自己不得不創建一個內部類,因爲HTMLEditor不是一個節點。所以我擴展矩形來做到這一點,並使用getChildren.add(htmlEditorWrapper)來嘗試添加它作爲一個節點。當然,當我運行該程序時,HTMLEditor不會顯示出來。

我的問題的要點:如何將HTMLEditor添加到窗格(它位於fxml文件中)?

import javafx.scene.layout.Pane; 
import javafx.scene.shape.Rectangle; 
import javafx.scene.web.HTMLEditor; 

/** 
* Gets the controller's outputPane (the console in the gui) 
* @author Matt 
* 
*/ 
public class OutputPanel{ 

    private static Pane pane; 
    private static HtmlEditorWrap htmlEditor = new HtmlEditorWrap(); 

    private static final OutputPanel outputPanel = new OutputPanel(); 

    private OutputPanel(){} 

    public static OutputPanel getInstance(){ 
     pane = Controller.getOutputPane(); 
     pane.getChildren().add(htmlEditor); 
     return outputPanel; 
    } 

    public void clear(){ 
     //htmlEditor.setHtmlText(); 
    } 

    public static void write(String text){ 
     htmlEditor.setHtmlText(text + "\n"); 
    } 

} 

class HtmlEditorWrap extends Rectangle{ 

    HTMLEditor htmlEditor = new HTMLEditor(); 

    public HtmlEditorWrap(){ 
     htmlEditor.setLayoutX(200); 
     htmlEditor.setLayoutY(200); 
     htmlEditor.setHtmlText("TESTING"); 
    } 

    public void setHtmlText(String text){ 
     htmlEditor.setHtmlText(text); 
    } 

} 

回答

3

其實HtmlEditorNode。嘗試直接添加它。 你是如何通過擴展Rectangle獲得編輯的?

+0

謝謝你Ramazan。我一定錯過了那裏,因爲我剛剛刪除了包裝類,放入HTMLEditor並且它工作。無論我之前做什麼都行不通。再次感謝您指出這一點。 – Matt 2013-04-05 07:08:43

相關問題