This is what I want to do:
When a single line in a text (let's say it's line
wrapped in a TextArea) goes too far let's say a
thousand words without the "\n" it's very hard to
perform band printing in java Graphics2D, as we only
will print the first part of this giant line, as much
as there is space for in the "band". My idea is to
split the line into minor lines, each of a max length
of characters, the same as the "band" allows(I use
monotype so it's OK).
For example: I like my new chevrolet and I drive with
it all day, might become: I like my new chevrolet\n
and I drive with it all day. This has to be made many
times if the string is very long. Recursively? In that
case, how?
This works to a degree, but only once, my max length
is here 24. I hope the rest can be understood.
String newStringBig =
textArea1.getText();
StringTokenizer newTokn = new
StringTokenizer(newStringBig,"\n");
int i=newTokn.countTokens();
while(newTokn.hasMoreTokens()) {
String newString= newTokn.nextToken("\n");
if (newString.length()>24)
{
String newString2 =
newString.substring(0,newString.lastIndexOf(" ",24));
newString=newString2+"\n"+newString.substring(newString.lastIndexOf("
",24))+newTokn.nextToken();
System.out.println(newString);
i=newTokn.countTokens();
}
++i;
}