0

I am running netbeans 8.1 and scene builder 2.0 with javaFX 8.0. I have just started messing around with the TextFlow container recently. In my program, I have wrapped a textArea inside the TextFlow container, but I cannot figure out how to use my textflow to count the number of lines being displayed inside the text area. Some people recommend using "flowcomposer", but I do not seem to have the flow composer option for some reason, and I'm not really sure how to import it...

Text wrapping is set to "true" inside my textarea...unfortunately, this means I cannot programmatically count lines "as-is" by counting the number of newlines, since wrapped text does not include a newline character.

Ultimately, not only do I want to be able to get the number of lines being displayed, but I also want to get the current line or position my cursor at a specific line/scroll to a specific line.

What do you guys think? Is textflow and flowcomposer the way to do this, or am I barking up the wrong tree? If this is indeed a viable way to accomplish the goals stated above, why am I not being able to use textflow to get the lines?

Any help would be greatly appreciated!:)

CodingAddict
  • 171
  • 3
  • 6
  • `TextFlow` will not provide this functionality for you. (It is primarily designed to add `Text` nodes, not `TextArea`s, to a layout that supports wrapping at word boundaries.) `TextArea` does not have the functionality to determine positions of individual character elements (at least, not without substantial hacking). You might consider the third-party control [RichTextFX](https://github.com/TomasMikula/RichTextFX) which has at least some of the things you need, if not all. I have no idea what `FlowComposer` is. – James_D Nov 12 '15 at 00:30
  • OK, I suppose you *could* try using `TextFlow` if you add every character as an independent `Text` object. Then you could examine the `layoutY` of each one to figure the number of lines (ugly), and implement the rest of your functionality in a similar manner. That wouldn't support editing though, which I guess you want as refer to a `TextArea`. – James_D Nov 12 '15 at 00:35
  • Thanks James. I really hope oracle implements this feature in future versions. I've already tried three different "solutions" and every one of them has been messy and imperfect so far. :( – CodingAddict Nov 12 '15 at 01:43
  • Why do you need this? Perhaps there is another solution to whatever you are actually trying to do? – James_D Nov 12 '15 at 01:45
  • It's a pretty massive project, and I will continually need the row count and line number for many different purposes. To use one example, I am trying to obtain various statistics, all of which require a total row count and the current row... It also needs to scroll down to the appropriate row of text at the press of a button, after entering the line number. – CodingAddict Nov 16 '15 at 05:00
  • Come to think of it...if there was SIMPLY a way to increment my counter every time a line is wrapped, I wouldn't need to make any significant changes to my program, which would be ideal. To do this, I would need to access the internal code, and somehow figure out what symbol/piece of binary is being used to make fx recognize the line-wrap, in other words, the internal "line-wrap-character" (if something like this indeed exists, which I would guess it needs to). I have done a lot of googling, and I still have no clue what this character might be... – CodingAddict Nov 16 '15 at 05:07
  • That probably wouldn't work as simply as you think: e.g. if the user enlarges the window you need to decrement your could as the text wrapping changes. Subclassing the `TextAreaSkin` (or the equivalent skin in RichTextFX) is probably the way to go here. – James_D Nov 16 '15 at 12:40

0 Answers0