If you just want to wrap your text without using StringTokenizer, I think
could give you a little help, here's a code and comments :
// Retrieve your string
String newStringBig = textArea1.getText();
// Prepare buffer
StringBuffer buffer = new StringBuffer();
// Prepare the limits
int begin = 0;
int end = 0;
// Start the process until we got the end of the string
while (end != (newStringBig.length()))
{
// If the beginning of string + maximum string (24) bigger than the
length of the string
if ((begin + 24) > (newStringBig.length() - 1))
{
// Okay, it's the end of string, use it as the end limit
end = newStringBig.length();
}
// If the rest of the string still bigger than 24 characters
else
// The end limit is the last occurrence of " " in our partial string
end = newStringBig.lastIndexOf(" ", (begin + 24));
}
// Append the partial string into buffer and add "+"
buffer.append(newStringBig.substring(begin, end) + "\n");
// Ok, we got the string...so just pass " " by adding one space
begin = end + 1;
}
// Show the result
System.out.println(buffer.toString());
Note :
If you have a word with the length bigger than or equal 24, it's possible
the code would be broken.