In my application, I use two tabs. In the first I posted an HtmlEditor, and in the second I posted a TextArea. The default HTML tab and when the user creates the HTML input, he can switch to TextArea to directly see / change the HTML source code. I added a listener to get rhe htmlText from the HtmlEditor and set it as text in TextArea, so the user can easily switch between HTML and source mode. Here is my listener:
@FXML private Tab htmlTab; @FXML private Tab sourceTab; @FXML private HTMLEditor htmlEditor; @FXML private TextArea textEditor; htmlTab.selectedProperty().addListener(new ChangeListener<Boolean>() { @Override public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { if (htmlTab.isSelected()) { htmlEditor.setHtmlText(textEditor.getText()); } } }); sourceTab.selectedProperty().addListener(new ChangeListener<Boolean>() { @Override public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { if (sourceTab.isSelected()) { textEditor.setText(htmlEditor.getHtmlText()); } } });
It works fine, but HtmlEditor automatically breaks the text into lines. When I switch to TextArea, all this on one line.
I was thinking of creating a helper method that takes a TextArea length attribute to count the number of characters and adds a new line character to each character "n", but maybe there is a better solution?
source share