我有一个FXML文件,其中有一个Pane作为其中一个条目,用于我们程序的输出。我想让这个窗格包含一个HTMLEditor。我对如何做到这一点感到有点困惑。该类使用Singleton模式作为推荐,我可以调用Controller来获取窗格。
然后我发现自己必须创建一个内部类,因为HTMLEditor不是Node。所以我扩展矩形来做到这一点,并使用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);
}
}