JavaFXHtmleditor中的Html源代码

JavaFXHtmleditor中的Html源代码,java,html,javafx,javafx-8,fxml,Java,Html,Javafx,Javafx 8,Fxml,有没有办法在源代码模式下使用javaFx-HTMLEditor,比如在firefox中选择show source code 我之所以需要它,是因为我想在编辑器中加载包含xml标记的字符串,而wigdet没有显示它们。不是HTMLEditor,也不是Webengine或Webview包含您需要的方法。我唯一发现的是在不同的文本区域显示html。也许这对你有帮助 import javafx.application.Application; import javafx.event.Event; imp

有没有办法在源代码模式下使用
javaFx-HTMLEditor
,比如在firefox中选择show source code


我之所以需要它,是因为我想在编辑器中加载包含xml标记的字符串,而wigdet没有显示它们。

不是HTMLEditor,也不是Webengine或Webview包含您需要的方法。我唯一发现的是在不同的文本区域显示html。也许这对你有帮助

import javafx.application.Application;
import javafx.event.Event;
import javafx.event.EventType;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.web.HTMLEditor;
import javafx.stage.Stage;

public class JavaFXApplication1 extends Application {

  @Override
  public void start(Stage primaryStage) {
    HTMLEditor editor = new HTMLEditor();
    editor.setHtmlText("<html>"
            + "<head>"
            + "<title>A Test</title>"
            + "</head>"
            + "<body>This is just a Test</body>"
            + "</html>");

    TextArea area = new TextArea();
    area.setText(editor.getHtmlText());
    editor.addEventHandler(EventType.ROOT, (Event event) -> {
      area.setText(editor.getHtmlText());
    });

    VBox root = new VBox();
    VBox.setVgrow(area, Priority.ALWAYS);
    root.getChildren().addAll(editor, area);

    Scene scene = new Scene(root, 300, 250);

    primaryStage.setScene(scene);
    primaryStage.show();
  }

  /**
   * @param args the command line arguments
   */
  public static void main(String[] args) {
    launch(args);
  }
}
导入javafx.application.application;
导入javafx.event.event;
导入javafx.event.EventType;
导入javafx.scene.scene;
导入javafx.scene.control.TextArea;
导入javafx.scene.layout.Priority;
导入javafx.scene.layout.VBox;
导入javafx.scene.web.HTMLEditor;
导入javafx.stage.stage;
公共类JavaFXApplication1扩展了应用程序{
@凌驾
公共无效开始(阶段primaryStage){
HTMLEditor编辑器=新的HTMLEditor();
editor.setHtmlText(“”)
+ ""
+“测试”
+ ""
+“这只是一个测试”
+ "");
TextArea=新建TextArea();
setText(editor.getHtmlText());
editor.addEventHandler(EventType.ROOT,(Event事件)->{
setText(editor.getHtmlText());
});
VBox root=新的VBox();
VBox.setVgrow(区域、优先级、始终);
root.getChildren().addAll(编辑器,区域);
场景=新场景(根,300,250);
初级阶段。场景(场景);
primaryStage.show();
}
/**
*@param指定命令行参数
*/
公共静态void main(字符串[]args){
发射(args);
}
}