Turn your Mobile Apps into m-commerce apps – Learn More!

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!



help getting text from jtextarea, line by line using the split method with a newline character will not work in this Rate Topic: -----

#1 KCvolunteer07  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 30-April 08


Dream Kudos: 0

Share |

help getting text from jtextarea, line by line

Post icon  Posted 30 April 2008 - 03:52 PM

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...
Was This Post Helpful? 0
  • +
  • -


#2 pbl  Icon User is offline

  • Java Lover who loves defau1t:
  • Icon

Reputation: 2130
  • View blog
  • Posts: 13,803
  • Joined: 06-March 08


Dream Kudos: 550

Re: help getting text from jtextarea, line by line

Posted 30 April 2008 - 08:01 PM

May be I am totally lost but

int nbLines = area1.getLineCount();

wouldn't do it ?
Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users