I have an Element
which I got from the Document
of a WebEngine
(JavaFX) and I use its getTextContent()
function from the body element to get the text content. The body element has the attribute contenteditable="true"
so I can write on it. However the string returned from getTextContent()
doesn't include line breaks. So
Line 1
Line 2
Line 3
On the body would return Line 1Line 2Line 3
I need it to include line breaks. How can I get it to do this?
Alternatively, I could use <TextArea>
instead of <body contenteditable="true"
if I can find a way to style each character. But I don't know how.
Thanks.
Subsequent lines will be inserted into the html as new
<div>
elements that are children of the<body>
element.You can see the HTML content by executing a snippet of javascript:
To get the individual lines, you need to iterate through the
<body>
's child nodes. Here's an example:If you want other options for creating styleable editable text, have a look at RichTextFX