HTMLEditor

Editor HTML

Com JavaFX e Maven

Arquivo: App.java
package minhaappjavafx.MinhaAppJavaFX;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.scene.web.HTMLEditor;
import javafx.stage.Stage;

public class App extends Application {

    @Override
    public void start(Stage primaryStage) {
        // Instantiate the HTML Editor
        HTMLEditor htmlEditor = new HTMLEditor();
        htmlEditor.setPrefHeight(400);

        // Set initial HTML content (Make sure contentEditable is true)
        String initialText = "<html><body contenteditable='true'><h2>Hello World!</h2><p>Start editing text here...</p></body></html>";
        htmlEditor.setHtmlText(initialText);

        // Button to extract and print the raw HTML code
        Button printButton = new Button("Get HTML Content");
        printButton.setOnAction(e -> {
            String rawHtml = htmlEditor.getHtmlText();
            System.out.println(rawHtml);
        });

        // Layout container
        VBox root = new VBox(10, htmlEditor, printButton);
       
        Scene scene = new Scene(root, 600, 450);
        primaryStage.setTitle("JavaFX HTMLEditor Example");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}