Read JTextPane line by line?

Once you get the root Element you can check to see how many child elements (ie. Lines) exist. Then you can get each child Element and use the start/end offset methods to get the text for that particular line.

Element root = textPane.getDocument(). GetDefaultRootElement(); Once you get the root Element you can check to see how many child elements (ie. Lines) exist.

Then you can get each child Element and use the start/end offset methods to get the text for that particular line. This would be more efficient than getting all the text in one big string and then splitting it again.

– Florian Peschka Aug 23 '10 at 19:40 1 Text components and a Document both has getText() methods that allow you to get all of the text or part of the text. – camickr Aug 24 '10 at 0:54.

The way that I've done this in the past is to use the getText method over my pane, then parse the string that is returned looking for the newline character '\n'.

From the top of the head I can't say if it is possible actually to read it line by line. Of course you could just split the text by the newline character and then you would get an array of strings, each line as its own element.Is this a problem in your case?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions