5 Replies Latest reply on Jul 23, 2012 8:21 AM by opfau

    Styling of text on character level

    opfau
      Hi,

      I am looking for a control to edit text. The text should be styled on character level. E. g. only character on index 2 has a red background but the whole text field has a blue background.

      Is there a control existing in javafx 2 to achieve this?

      Regards
      Oliver
        • 1. Re: Styling of text on character level
          jsmith
          HTMLEditor
          • 2. Re: Styling of text on character level
            opfau
            Is it possible to switch off the controls and use the edit area only? The user shall be able to edit the text, but not the colors.
            • 3. Re: Styling of text on character level
              jsmith
              Is it possible to switch off the controls and use the edit area only?
              Yes, there are ways to customize it:
              https://gist.github.com/2514709 code sample
              Re: Customizing  HTMLEditor element "Thread: Customizing HTMLEditor element"
              http://stackoverflow.com/questions/10075841/how-to-hide-the-controls-of-htmleditor (last section has info on hiding the toolbar - is done by code, but you might be able to achieve the same by a css stylesheet - which would be a better implementation - dgrieve's comment was "You can extract html-editor.css from jfxrt.jar to see what styles it uses.").

              There is also a jira to provide an api to control HTMLEditor allow programmatic control of editing capability, but that hasn't been actioned yet.

              Additionally you can use a WebView with contenteditable="true" see:
              http://stackoverflow.com/questions/10685395/webview-with-contenteditable-cannot-be-focused-programmatically
              1 person found this helpful
              • 4. Re: Styling of text on character level
                opfau
                Thanks a lot
                • 5. Re: Styling of text on character level
                  opfau
                  After investigation, the WebView or HTMLEditor is quite hard to use for my use case. I want to show the styled text (on character level)...after changing the style shall be reset (on character level). For instance a green background of a char shall be now white. After editing the text is needed for further processing. If I get the text form WebView or HTMLEditor, I get also the html tags. The html code could be removed, but if the user enters something like html, it will be removed also.
                  Best would be a TextField with styling capability on character level, but it seems like that I have to implement this on my own?