2013-04-05 111 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

相关问题