My program allows the user to load a file into a jtextarea, and I need to know how to get each individual line of the jtextarea, based on the size of the jtextarea. If the size of the frame changes, the size of the jtextareas change, so it has to get each line of the jtextarea no matter what the width of the jtextarea is. Also, WORDWRAP is being used, so I can't simply split the text of the jtextarea at every newline. Does anyone know what I can do? Here's something I tried...that didn't work:
[code]
String file1 = area1.getText();
int width1=area1.getWidth(); //width of the jtextarea
int file1Length = area1.getLineCount(); //holds the length of the first array
String[] text1= new String[file1Length]; //this would hold each line of the code as a different element
int begin=0;
int end=width1;
for(int p=0;p<file1Length;p++)
{
area1.select(begin, end);
text1[p]=area1.getSelectedText(); //selects the text between the start of the new line and the end
begin+=end;
end*=2;
}[code]
Like I said...that code doesn't do what i want it to do...
You're Browsing As A Guest! Register Now... |
||
|
Become a Java Expert!
Join 415,728 Java Programmers for FREE! Get instant access to thousands
of Java experts, tutorials, code snippets, and more! There are 1,697 people online right now.Registration is fast and FREE... Join Now!
|
||
Page 1 of 1
help getting text from jtextarea, line by line using the split method with a newline character will not work in this
Page 1 of 1


Ask A New Question
Reply





MultiQuote






|