Reading JTextPane line by line
Is there a way to read the content JTextPane
line by line? Like BufferedReader?
Element root = textPane.getDocument().getDefaultRootElement();
Once you get the root element, you can check how many children (i.e. rows) there are. Then you can get each child and use the start / end offset methods to get the text for that particular line.
This will be more efficient than getting all the text on one big line and then splitting it up.
The way I have done this in the past is to use the getText method on top of my panel and then parse the string that is returned looking for the newline character '\ n'.
Can you explain what you are trying to do? From the top of my head, I can't tell if it really can be read line by line. Of course, you could just split the text on a newline and then you get an array of strings, each string will be its own element. Is this a problem in your case?