?
Solved

JTextArea - need to remove the first line appended.

Posted on 2008-11-02
5
Medium Priority
?
776 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 60

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 60

Accepted Solution

by:
Kevin Cross earned 2000 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 60

Expert Comment

by:Kevin Cross
ID: 22870756
Glad that helped.

Happy coding!

Regards,
Kevin
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month9 days, 11 hours left to enroll

762 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