[英]Html source in javafx HTMLEditor
Is there a way to use javaFx HTMLEditor
in source mode, like when you select show source code in firefox? 有没有办法在源代码模式下使用javaFx HTMLEditor
,例如在firefox中选择显示源代码时?
I need this because I want to load strings which include xml tags in the editor and the wigdet is not showing them. 我需要这样做是因为我想在编辑器中加载包含xml标记的字符串,而wigdet没有显示它们。
Not HTMLEditor nor Webengine or Webview contains a method like your needs. HTMLEditor或Webengine或Webview都不包含您需要的方法。 The only thing I've found is something to display the html in a different textarea. 我发现的唯一一件事是在不同的textarea中显示html的内容。 Maybe this will help you. 也许这会对您有所帮助。
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.