Terrance Samson wrote:And here's the REALLY IMPORTANT part: I can NOT just have it load the text from a file directly - I MUST be able to just set the text to a string in memory. I may get that string from a file or not. And then I must be able to extract text from the JTextPane/JEditorPane/whatever control and store it in a string WITHOUT necessarily saving it into a file or putting it onto the clipboard.
Terrance Samson wrote:As you can see, it's reading straight from a file, with a FileInputStream as the parameter to the read function. I suppose it might be possible to substitute that with some kind of memory stream and use that instead, but I wouldn't want to assume (honestly, I'm a bit rusty with Java because I do nearly all programming in C# and it's been more than a decade since I used Java, but I just recently started again).
Terrance Samson wrote:EDIT: Whoops! I just realized that the transferTo function is only in Java 9 and later, but I'm using Java 8, and I just checked and it doesn't seem to recognize the function! Is there a different function or way to do the same thing?
Terrance Samson wrote:EDIT: Well now I've tested that stuff and it looks like Wordpad is not compatible with DOC files, but yes my programs are, and it seems that LibreOffice is the odd one that doesn't really match anything else. Well, that's good to know!
So I guess LibreOffice makes this automatic adjustment and Wordpad doesn't.
Maybe Java's Swing component doesn't handle all possible implementations of the RTF specification.
Tim Moores wrote:While Wordpad can open RTFs and DOCs in general, it's a really limited app. I wouldn't take its behavior to signify anything about how something is working correctly or not. In general, RTF is a good format for exchanging styled/formatted text. Certainly much better than DOC or DOCX if you don’t know which word processors might be used to handle it, anyway.
Tim Moores wrote:All standard word processors can do this, and all of them let you turn it off. In LibreOffice: Tools -> AutoCorrect -> AutoCorrect Options -> Localized Options. That's another area where Wordpad shows its limitations.
Tim Moores wrote:Indeed. It handles only a subset of RTF, and is buggy at that, too. See https://bugs.openjdk.java.net/browse/JDK-4723383 to get an idea how long people have been complaining about that, and how long nothing has been done about it.
Terrance Samson wrote:As a side note, I also noticed that when using JavaFX, it seems to handle HTML formatted text just fine, but doesn't even have anything compatible with RTF at all, as far as I can tell.