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

JTextArea - need to remove the first line appended.

Posted on 2008-11-02
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?

Question by:OwenMoriarty
  • 3
  • 2
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.

Author Comment

ID: 22866915
something like???

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

returns an array ? is this valid Java ?

LVL 59

Accepted Solution

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) {

Open in new window


Author Comment

ID: 22870690
Tks for that,
All working now.

LVL 59

Expert Comment

by:Kevin Cross
ID: 22870756
Glad that helped.

Happy coding!


Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

Title # Comments Views Activity
Android studio getdrawable(int) is deprecated 4 114
java stored proc example 9 44
How to determine if a string is a valid SHA value 7 35
Glassfish admin console not working 1 32
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

840 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