Kiraged
Kiraged

Reputation: 519

Highlight text in HTMLEditor JavaFx

Hello i'm trying to make a search system and it works like this:

  1. You press ctrl + f
  2. A text dialogue shows up
  3. The text in the text dialogue you entered will highlight in the HTMLEditor

So i'm having problems with the third step I can't find any method about highlighting or find anything on google for HTMLEditor.

So my question is, is it possible to highlight text in a HTMLEditor and if so how?

Upvotes: 0

Views: 1769

Answers (2)

dankito
dankito

Reputation: 1108

If you don't mind using reflection, it can be done natively in Java code.

See my answer here: https://stackoverflow.com/a/49350328/8837882.

Upvotes: 0

jewelsea
jewelsea

Reputation: 159416

Possible Approach

There is a similar question for search & highlight functionality in WebView:

Perhaps you could use an adjustment of that approach (internally the HTMLEditor is implemented as a WebView I believe, though I could be wrong).

You might be able to use some techniques for customizing the existing HTMLEditor to get UI controls for executing searches into the toolbar of the HTMLEditor.

Alternatives

Rather than using HTMLEditor you could either use:

  • A WebView with ContentEditable.
  • A native JavaFX rich text editor.
  • A markdown editor (there are native JavaFX solutions for this if you google JavaFX markdown).
  • A WebView running an embedded third party JavaScript based HTMLEditor which includes search and replace functionality (there are many of these, you can just run a google search to evaluate alternatives).

If it were me, I'd probably choose the Markdown editor approach if the editor was for a semi-technical audience or the third party JavaScript editor in WebView if the audience was non-technical and required a WYSIWYG HTML editor with a ribbon.

Upvotes: 2

Related Questions