Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 802
  • Last Modified:

JTextArea - need to remove the first line appended.

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
OwenMoriarty
Asked:
OwenMoriarty
  • 3
  • 2
1 Solution
 
Kevin CrossChief Technology OfficerCommented:
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
 
OwenMoriartyAuthor Commented:
something like???

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

returns an array ? is this valid Java ?

Tks,
Owen.
0
 
Kevin CrossChief Technology OfficerCommented:
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
 
OwenMoriartyAuthor Commented:
Tks for that,
All working now.

Rds,
Owen.
0
 
Kevin CrossChief Technology OfficerCommented:
Glad that helped.

Happy coding!

Regards,
Kevin
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now