I'm building an application that displays text from character arrays. An objective is not to leave compromising Strings throughout the system memory. I haven't found a way to eliminate Strings from the JTextField / swing.text.Document classes. In looking at the source code, such as I can, the use of Strings goes very deep.
Does anyone have a JTextField-like class that has only visible and clearable character arrays for displayed data? Must have full Unicode/BIDI support, too.
However, the problem is now how to put to the JTextField, not to get from it, as the suggested getText(0, count, Segment) method works fine for getting characters from the Document / JTextField.
I have tried putting a phony String of the necessary length via insertString(0, spacer, null) followed by a getText(0, count, Segment) then filling the Segment.array with the actual, sensitive characters. Amazingly, this seems to work for low order Unicode (ASCII), but not for full Unicode text. Note that Segments are supposed to provide read-only access and that it's far from obvious that changing the Segment values should change the displayed text.
Inside AbstractDocument is a mysterious "data" class that handles the internal workings of the Document. I'm presumably working with the PlainDocument, how do I determine what this "data" class looks like? AbstractDocument has only String-based methods operating on the data class. All very complicated at my level.
Suggestions are appreciated. Being as lazy as the next guy, I was hoping this was a general enough problem that someone else might have solved it!
Thanks to JavaRanch's suggestion to look at the Java sources and to its pointing me to the sources, I've been able to come up with a String-less JTextArea (not JTextField). In case anyone else is interested, here's what I did:
I cloned javax.swing.text.GapVector to another class KGapVector initialized by providing an external char, rather than an int initialSize.
I cloned javax.swing.text.GapContent to another class KGapContent initialized by providing an external char, rather than an int initialSize and using KGapVector for its text storage. The
MarkVector continues to extend the original GapVector. KGapContent has a method insertChars supplementing the usual insertString method.
The new classes are applied by creating a char in the app and using that to create a new KGapContent. Then the KGapContent object is used to instantiate a PlainDocument that is set into the JTextArea with a setDocument method. The JTextAreaComponentOrientation must be set BEFORE the setDocument. The app places char text into the JTextArea via the new insertChars method and cleans up by cleaning the app's char that set the KGapContent. All input from the JTextArea is via the Segment returned by the usual JTextArea.getText method.
Seems to work OK.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com