繁体   English   中英

javafx HTMLEditor中的HTML源代码

[英]Html source in javafx HTMLEditor

有没有办法在源代码模式下使用javaFx HTMLEditor ,例如在firefox中选择显示源代码时?

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

HTMLEditor或Webengine或Webview都不包含您需要的方法。 我发现的唯一一件事是在不同的textarea中显示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);
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM