I made a Tool where it is possible to write text in a HTMLEditor in plain text. The text is shown as HTML Code in a textarea. I put a KeyEvent-Handler to solve this problem, but if I change something afterwards with my mouse, not every change is indicated. My Problem: is it possible to implement a ChangeListener to the HTMLEditor, so that every change is displayed? Thanks a lot!!
ublic class JavaFXHtmlEditor extends Application {
@Override
public void start(Stage primaryStage) {
VBox root = new VBox();
root.setSpacing(10);
HBox up = new HBox();
up.setPrefHeight(300);
up.setPrefWidth(500);
up.setAlignment(Pos.CENTER);
HBox down = new HBox();
down.setPrefHeight(200);
up.setPrefWidth(400);
down.setAlignment(Pos.CENTER);
HTMLEditor htmlEditor = new HTMLEditor();
TextArea textArea = new TextArea();
textArea.setWrapText(true);
up.getChildren().add(htmlEditor);
down.getChildren().add(textArea);
root.getChildren().addAll(up, down);
htmlEditor.addEventHandler(KeyEvent.KEY_RELEASED, new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent event) {
textArea.setText(htmlEditor.getHtmlText());
}
});
htmlEditor.addEventHandler(MouseEvent.MOUSE_RELEASED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
textArea.setText(htmlEditor.getHtmlText());
}
});
Scene scene = new Scene(root, 600, 400);
primaryStage.setTitle("Plain Text to HTML");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
I solved it now this way
htmlEditor.addEventHandler(InputEvent.ANY, new EventHandler<InputEvent>() {
@Override
public void handle(InputEvent event) {
textArea.setText(htmlEditor.getHtmlText());
}
});