I'm trying to read a .java file into a JTextArea and no matter what method I use to read in the file the formatting is never preserved. The actual code is ok but the comments always get messed up. Here are my attempts.
I'm not sure if I used tabs or not, that seems like a likely reason. Also I didn't know that I could specify how tabs were read. Is that a JTextPane only setting? or will I be able to do that is JTextArea, which is what I am using.
Edit: I looked at the API closer and there is a setTabSize() method in the JTextArea class. I will look into that, thanks for the help everyone.
Paul Clapham wrote:By the way I wouldn't have written any of that code. Here's the code I would have written:
Surely you mean this:
After all, you should always close your resources.
I had seen the read() method in the JTextComponent method list, but didn't use it immediately. The overall goal of this is for me to be able to create a text editor for .java and other files. Swing is also an area of Java where I am very weak, which is another reason I am doing this project. Thank you all for your advice. I am sure that I will have more questions as I make progress in this project.
subject: How to keep formatting while reading files