Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8092278

Text should have API for selecting group of characters based on their position similar to the DOM's Range.


    • Type: Enhancement
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: tbd
    • Component/s: javafx
    • Labels:


      Text and/or TextFlow should have an API for getting a character or group of characters based on their position, similar to the DOM's Range. (See: http://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html ) . This is very useful for enabling features like text selection, copy-pasting, and getting the characters under the pointer/cursor during hover/click events.

      My use case: I am developing an application for learning foreign languages via reading texts. A major component of this is that the text the user has chosen will be displayed, and hovering over a word will cause a pop-up dictionary to bring up suggested definitions for the word under the cursor. I also have other plans for different actions a user can take on the word under cursor, ie bringing up a context menu, etc. There are certainly workarounds, such as splitting up each word into a seperate text node, but this becomes much more difficult in a language like Japanese in which words aren't delineated in a text by white space. There are certainly parsers, such as Mecab for Japanese, but implementing these parsers for each possible language is impossible (it would be necessary to implement Mecab for Japanese, a different one for Chinese, another for Korean, etc), also, the parsers are far from perfect and fall down quite frequently on things like prefixes and suffixes, verb tense, etc. The easiest solution, and one used by the popular browser pop-up dictionary Rikaichan (http://www.polarcloud.com/rikaichan/) and all the others whose source code I've looked at is to get the character under cursor, then work forward through the string, comparing the possibilities against entries in the dictionary until the entries come up blank or the end of the line is reached. I plan to make my application capable of using several popular opensource dictionary formats, such as StarDict, for which dictionaries are widely available on the internet in hundreds of languages, and then have the user provide their own dictionaries for the language(s) of their choosing, thus avoiding the problem of needing multiple parsers.

      I have noticed that the TextArea and TextField have some methods for dealing with this, though I don't know if it's possible to get a Selection from the text like the DOM's range, by providing two sets of x,y coordinates. This can be useful, for grabbing text without it being explicitly hovered, clicked or selected. Still, Text and TextFlow do not seem to have any API in this regard at all. Thanks.


          Issue Links



              • Assignee:
                ekendojfx Edub Kendo (Inactive)
              • Votes:
                1 Vote for this issue
                7 Start watching this issue


                • Created: