Solved

JTextArea - need to remove the first line appended.

Posted on 2008-11-02
5
759 Views
Last Modified: 2013-11-23
I have a JTextArea in a GUI which will have appended lines of text during the operation of the GUI, but I also want the users to be able to remove the first added line of text. Each line has been appeneded using a newline.

Any ideas or suggestions?

Tks,
Owen.
0
Comment
Question by:OwenMoriarty
  • 3
  • 2
5 Comments
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 22864100
You could try using String.split() or StringTokenizer on the "\n" or "\n\r" as delimeters.  Then you will have each line of the JTextArea to manipulate as you see fit.
0
 

Author Comment

by:OwenMoriarty
ID: 22866915
something like???

String[] myArray = myString.split("\n")

returns an array ? is this valid Java ?

Tks,
Owen.
0
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 22867163
That is what I was talking about.

Give this a try to test out your code. :)

If you find that you are getting line breaks in the result, then you should split on "\n\r" which is carriage return and line feed.
String myString = "My test\nstring has line breaks\nin it.\n";
		String[] myArray = myString.split("\n");
		
		for (String s : myArray) {
			System.out.println(s);
		}

Open in new window

0
 

Author Comment

by:OwenMoriarty
ID: 22870690
Tks for that,
All working now.

Rds,
Owen.
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 22870756
Glad that helped.

Happy coding!

Regards,
Kevin
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupSum6 challenge 6 86
servlet requestdispatcher include and forward differences 1 32
pagenation logic how it is working in my code 1 31
Problem to Alipay 10 23
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question