Example:
package javafx_html;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextAreaBuilder;
import javafx.scene.layout.VBox;
import javafx.scene.layout.VBoxBuilder;
import javafx.scene.web.HTMLEditor;
import javafx.scene.web.HTMLEditorBuilder;
import javafx.stage.Stage;
/**
*
* @web http://java-buddy.blogspot.com/
*/
public class JavaFX_HTMLeditor extends Application {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("java-buddy.blogspot.com");
Group root = new Group();
final HTMLEditor htmlEditor = HTMLEditorBuilder.create()
.prefHeight(200)
.prefWidth(400)
.build();
final TextArea htmlText = TextAreaBuilder.create()
.prefWidth(400)
.wrapText(true)
.build();
ScrollPane scrollPane = new ScrollPane();
scrollPane.getStyleClass().add("noborder-scroll-pane");
scrollPane.setContent(htmlText);
scrollPane.setFitToWidth(true);
scrollPane.setPrefHeight(180);
Button buttonUpdate = new Button("Update");
buttonUpdate.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent t) {
htmlText.setText(htmlEditor.getHtmlText());
}
});
VBox vBox = VBoxBuilder.create()
.children(htmlEditor, htmlText, buttonUpdate)
.build();
root.getChildren().add(vBox);
primaryStage.setScene(new Scene(root, 500, 400));
primaryStage.show();
}
}
Next:
- Save HTMLEditor generated code in file